~reedwade/wee-matter

e5546e249750d9d386908d0c6e3185be127ed8f1 — Reed Wade 7 months ago adfdd65
Handle mattermost commands
3 files changed, 30 insertions(+), 1 deletions(-)

M main.py
M wee_matter/commands.py
M wee_matter/http.py
M main.py => main.py +1 -1
@@ 7,7 7,7 @@ from wee_matter.room import (handle_multiline_message_cb, room_input_cb,

from wee_matter.commands import (matter_command_cb, reply_command_cb,
                                 react_command_cb, unreact_command_cb,
                                 delete_post_command_cb)
                                 delete_post_command_cb, matter_command_cb)

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

M wee_matter/commands.py => wee_matter/commands.py +10 -0
@@ 188,6 188,14 @@ def delete_post_command_cb(data, buffer, args):

    return weechat.WEECHAT_RC_OK

def matter_command_cb(data, buffer, command):
    server = wee_matter.server.get_server_from_buffer(buffer)
    channel_id = weechat.buffer_get_string(buffer, "localvar_channel_id")

    wee_matter.http.run_post_command(channel_id, "/{}".format(command), server, "singularity_cb", buffer)

    return weechat.WEECHAT_RC_OK

def setup_commands():
    weechat.hook_command(
        "matter",


@@ 219,6 227,8 @@ def setup_commands():
    weechat.hook_command("unreact", "Unreact to a post", "<post-id> <emoji-name>", "Unreact to a post", "", "unreact_command_cb", "")
    weechat.hook_command("delete", "Delete a post", "<post-id>", "Delete a post", "", "delete_post_command_cb", "")

    weechat.hook_command("matter", "Send a command", "<message>", "Send a command", "", "matter_command_cb", "")

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

    weechat.hook_completion("irc_channels", "complete channels for mattermost", "channel_completion_cb", "")

M wee_matter/http.py => wee_matter/http.py +19 -0
@@ 202,6 202,25 @@ def run_post_post(post, server, cb, cb_data):
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_post_command(channel_id, command, server, cb, cb_data):
    url = wee_matter.server.server_root_url(server) + "/api/v4/commands/execute"
    params = {
        "channel_id": channel_id,
        "command": command,
    }

    weechat.hook_process_hashtable(
        "url:" + url,
        {
            "failonerror": "1",
            "httpheader": "Authorization: Bearer " + server.user_token,
            "postfields": json.dumps(params),
        },
        30 * 1000,
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel_posts(channel_id, server, cb, cb_data):
    url = wee_matter.server.server_root_url(server) + "/api/v4/channels/" + channel_id + "/posts"
    weechat.hook_process_hashtable(