~tardypad/wee-most

9d0406e52b5fd04b941c86c8489fd5626304d7ef — Damien Tardy-Panis 2 months ago 1584fc7
Move completion functions and setup to new completions file
M main.py => main.py +6 -4
@@ 1,14 1,15 @@
import weechat

from wee_most.channel import (handle_multiline_message_cb, channel_input_cb,
                             buffer_switch_cb, channel_completion_cb,
                             private_completion_cb,
                             buffer_switch_cb,
                             channel_click_cb)

from wee_most.server import (config_server_buffer_cb)

from wee_most.server import (server_completion_cb, config_server_buffer_cb)
from wee_most.commands import (mattermost_command_cb)

from wee_most.commands import (mattermost_command_cb, slash_command_completion_cb)
from wee_most.completions import (channel_completion_cb, private_completion_cb,
                                  server_completion_cb, slash_command_completion_cb)

from wee_most.websocket import (receive_ws_callback, ws_ping_cb,
                                  reconnection_loop_cb)


@@ 37,6 38,7 @@ weechat.register(
)

wee_most.commands.setup_commands()
wee_most.completions.setup_completions()
config.setup()
wee_most.server.auto_connect()


M wee_most/__init__.py => wee_most/__init__.py +1 -0
@@ 1,5 1,6 @@
from wee_most import file
from wee_most import commands
from wee_most import completions
from wee_most import config
from wee_most import http
from wee_most import post

M wee_most/channel.py => wee_most/channel.py +0 -17
@@ 118,23 118,6 @@ def remove_buffer_hydratating(channel_id):
def get_buffer_from_channel_id(channel_id):
    return channel_buffers[channel_id]

def private_completion_cb(data, completion_item, current_buffer, completion):
    for server in servers.values():
        for channel in server.channels.values():
            buffer_name = weechat.buffer_get_string(channel.buffer, "short_name")
            weechat.hook_completion_list_add(completion, buffer_name, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

def channel_completion_cb(data, completion_item, current_buffer, completion):
    for server in servers.values():
        weechat.hook_completion_list_add(completion, server.id, 0, weechat.WEECHAT_LIST_POS_SORT)
        for team in server.teams.values():
            for channel in team.channels.values():
                buffer_name = weechat.buffer_get_string(channel.buffer, "short_name")
                weechat.hook_completion_list_add(completion, buffer_name, 0, weechat.WEECHAT_LIST_POS_SORT)

    return weechat.WEECHAT_RC_OK

def mark_channel_as_read(buffer):
    server = wee_most.server.get_server_from_buffer(buffer)
    channel_id = weechat.buffer_get_string(buffer, "localvar_channel_id")

M wee_most/commands.py => wee_most/commands.py +0 -12
@@ 197,13 197,6 @@ def command_delete(args, buffer):

    return weechat.WEECHAT_RC_OK

def slash_command_completion_cb(data, completion_item, current_buffer, completion):
    slash_commands = ["away", "code", "collapse", "dnd", "echo", "expand", "groupmsg", "header", "help", "invite", "invite_people", "join", "kick", "leave", "logout", "me", "msg", "mute", "offline", "online", "purpose", "rename", "search", "settings", "shortcuts", "shrug", "status"]

    for slash_command in slash_commands:
        weechat.hook_completion_list_add(completion, slash_command, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

def write_command_error(args, message):
    buffer = weechat.buffer_search_main()
    weechat.prnt(buffer, message + " \"/mattermost " + args + "\" (help on command: /help mattermost)")


@@ 220,8 213,3 @@ def setup_commands():
    )

    weechat.hook_focus("chat", "channel_click_cb", "")

    weechat.hook_completion("irc_channels", "complete channels for Mattermost", "channel_completion_cb", "")
    weechat.hook_completion("irc_privates", "complete dms/mpdms for Mattermost", "private_completion_cb", "")
    weechat.hook_completion("mattermost_server_commands", "complete server names for Mattermost", "server_completion_cb", "")
    weechat.hook_completion("mattermost_slash_commands", "complete Mattermost slash commands", "slash_command_completion_cb", "")

A wee_most/completions.py => wee_most/completions.py +41 -0
@@ 0,0 1,41 @@

import weechat
import wee_most

from wee_most.globals import servers

def channel_completion_cb(data, completion_item, current_buffer, completion):
    for server in servers.values():
        weechat.hook_completion_list_add(completion, server.id, 0, weechat.WEECHAT_LIST_POS_SORT)
        for team in server.teams.values():
            for channel in team.channels.values():
                buffer_name = weechat.buffer_get_string(channel.buffer, "short_name")
                weechat.hook_completion_list_add(completion, buffer_name, 0, weechat.WEECHAT_LIST_POS_SORT)

    return weechat.WEECHAT_RC_OK

def private_completion_cb(data, completion_item, current_buffer, completion):
    for server in servers.values():
        for channel in server.channels.values():
            buffer_name = weechat.buffer_get_string(channel.buffer, "short_name")
            weechat.hook_completion_list_add(completion, buffer_name, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK


def server_completion_cb(data, completion_item, current_buffer, completion):
    for server_id in servers:
        weechat.hook_completion_list_add(completion, server_id, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

def slash_command_completion_cb(data, completion_item, current_buffer, completion):
    slash_commands = ["away", "code", "collapse", "dnd", "echo", "expand", "groupmsg", "header", "help", "invite", "invite_people", "join", "kick", "leave", "logout", "me", "msg", "mute", "offline", "online", "purpose", "rename", "search", "settings", "shortcuts", "shrug", "status"]

    for slash_command in slash_commands:
        weechat.hook_completion_list_add(completion, slash_command, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

def setup_completions():
    weechat.hook_completion("irc_channels", "complete channels for Mattermost", "channel_completion_cb", "")
    weechat.hook_completion("irc_privates", "complete dms/mpdms for Mattermost", "private_completion_cb", "")
    weechat.hook_completion("mattermost_server_commands", "complete server names for Mattermost", "server_completion_cb", "")
    weechat.hook_completion("mattermost_slash_commands", "complete Mattermost slash commands", "slash_command_completion_cb", "")

M wee_most/http.py => wee_most/http.py +1 -1
@@ 15,7 15,7 @@ from wee_most.file import file_get_cb

from wee_most.server import (connect_server_cb, connect_server_teams_cb,
                               connect_server_team_channels_cb,
                               connect_server_users_cb, server_completion_cb,
                               connect_server_users_cb,
                               connect_server_team_channel_cb, connect_server_team_cb,
                               new_user_cb)


M wee_most/server.py => wee_most/server.py +0 -5
@@ 135,11 135,6 @@ def get_server_from_buffer(buffer):
    server_id = weechat.buffer_get_string(buffer, "localvar_server_id")
    return servers[server_id]

def server_completion_cb(data, completion_item, current_buffer, completion):
    for server_id in servers:
        weechat.hook_completion_list_add(completion, server_id, 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

def connect_server_team_channel(channel_id, server):
    wee_most.channel.register_buffer_hydratating(channel_id)
    wee_most.http.enqueue_request(