~tardypad/wee-most

0d8bf9cb791c70255097acc2e3915acf2f9676e3 — Damien Tardy-Panis 3 months ago 1b32302
Make all commands subcommands of /mattermost

Prevents conflicts with other plugins
Can still be added via aliases if needed for convenience
3 files changed, 44 insertions(+), 22 deletions(-)

M README.md
M main.py
M wee_most/commands.py
M README.md => README.md +9 -4
@@ 55,10 55,15 @@ Mouse click or select a line print the short post id in the input field.
Some command uses this id to interact with posts.

```
/reply abc Yeah you right !
/react abc rofl
/react abc 100
/delete abc
/mattermost reply abc Yeah you right !
/mattermost react abc rofl
/mattermost react abc 100
/mattermost delete abc
```

You can add aliases for some of these commands (if there's no conflict with other plugins)
```
alias add reply /mattermost reply
```

## Buffers display

M main.py => main.py +1 -3
@@ 8,9 8,7 @@ from wee_most.channel import (handle_multiline_message_cb, channel_input_cb,

from wee_most.server import (server_completion_cb, config_server_buffer_cb)

from wee_most.commands import (matter_command_cb, reply_command_cb,
                                 react_command_cb, unreact_command_cb,
                                 delete_post_command_cb, slash_command_completion_cb)
from wee_most.commands import (mattermost_command_cb, slash_command_completion_cb)

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

M wee_most/commands.py => wee_most/commands.py +34 -15
@@ 63,7 63,7 @@ def slash_command(args, buffer):

    return weechat.WEECHAT_RC_OK

def matter_command_usage(buffer):
def mattermost_command_usage(buffer):
    weechat.prnt(buffer,
        (
            "Usage: \n"


@@ 71,12 71,16 @@ def matter_command_usage(buffer):
            "    /mattermost connect <server-name>\n"
            "    /mattermost disconnect <server-name>\n"
            "    /mattermost command <mattermost-command>\n"
            "    /mattermost reply <post-id> <message>\n"
            "    /mattermost react <post-id> <emoji-name>\n"
            "    /mattermost unreact <post-id> <emoji-name>\n"
            "    /mattermost delete <post-id>\n"
        )
    )

def matter_command_cb(data, buffer, command):
def mattermost_command_cb(data, buffer, command):
    if 0 == len(command.split()):
        matter_command_usage(buffer)
        mattermost_command_usage(buffer)
        return weechat.WEECHAT_RC_ERROR

    prefix, _, args = command.partition(" ")


@@ 89,13 93,21 @@ def matter_command_cb(data, buffer, command):
        return disconnect_command(args, buffer)
    if prefix == "command":
        return slash_command(args, buffer)
    if prefix == "reply":
        return reply_command(args, buffer)
    if prefix == "react":
        return react_command(args, buffer)
    if prefix == "unreact":
        return unreact_command(args, buffer)
    if prefix == "delete":
        return delete_command(args, buffer)

    return weechat.WEECHAT_RC_ERROR

def reply_command_usage(buffer):
    weechat.prnt(buffer, "Usage: /reply <post-id> <message>")

def reply_command_cb(data, buffer, args):
def reply_command(args, buffer):
    if 2 != len(args.split(' ', 1)):
        reply_command_usage(buffer)
        return weechat.WEECHAT_RC_ERROR


@@ 128,7 140,7 @@ def reply_command_cb(data, buffer, args):
def react_command_usage(buffer):
    weechat.prnt(buffer, "Usage: /react <post-id> <emoji-name>")

def react_command_cb(data, buffer, args):
def react_command(args, buffer):
    if 2 != len(args.split()):
        react_command_usage(buffer)
        return weechat.WEECHAT_RC_ERROR


@@ 147,7 159,7 @@ def react_command_cb(data, buffer, args):
def unreact_command_usage(buffer):
    weechat.prnt(buffer, "Usage: /unreact <post-id> <emoji-name>")

def unreact_command_cb(data, buffer, args):
def unreact_command(args, buffer):
    if 2 != len(args.split()):
        unreact_command_usage(buffer)
        return weechat.WEECHAT_RC_ERROR


@@ 163,10 175,10 @@ def unreact_command_cb(data, buffer, args):

    return weechat.WEECHAT_RC_OK

def delete_post_command_cb_usage(buffer):
def delete_post_command_usage(buffer):
    weechat.prnt(buffer, "Usage: /delete <post-id>")

def delete_post_command_cb(data, buffer, args):
def delete_post_command(args, buffer):
    if 1 != len(args.split()):
        delete_post_command_usage(buffer)
        return weechat.WEECHAT_RC_ERROR


@@ 198,7 210,11 @@ def setup_commands():
            "server add <server-name> ||"
            "connect <server-name> ||"
            "disconnect <server-name> ||"
            "<mattermost-command>"
            "<mattermost-command> ||"
            "reply <post-id> <message> ||"
            "react <post-id> <emoji-name> ||"
            "unreact <post-id> <emoji-name>  ||"
            "delete <post-id>"
        ),
        # Description
        (


@@ 206,6 222,10 @@ def setup_commands():
            "connect Mattermost servers\n"
            "disconnect Mattermost servers\n"
            "send a plain Mattermost command\n"
            "reply to a post\n"
            "react to a post\n"
            "unreact to a post\n"
            "delete a post\n"
        ),
        # Completions
        (


@@ 213,16 233,15 @@ def setup_commands():
            "connect ||"
            "disconnect %(mattermost_server_commands) ||"
            "command %(mattermost_slash_commands) ||"
            "reply ||"
            "react ||"
            "unreact ||"
            "delete"
        ),
        "matter_command_cb",
        "mattermost_command_cb",
        ""
    )

    weechat.hook_command("reply", "Reply to a post", "<post-id> <message>", "Reply to a post", "", "reply_command_cb", "")
    weechat.hook_command("react", "React to a post", "<post-id> <emoji-name>", "React to a post", "", "react_command_cb", "")
    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_focus("chat", "channel_click_cb", "")

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