From c311c37fa99fe31cead934a26646f3235b2c96a8 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 6 Nov 2018 19:42:44 +0100 Subject: Add /slack help command Fixes #363 --- wee_slack.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index 08cf0d4..4bdb229 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3584,6 +3584,30 @@ def slack_command_cb(data, current_buffer, args): return w.WEECHAT_RC_OK +@utf8_decode +def command_help(data, current_buffer, args): + """ + /slack help + Print help for /slack commands + """ + args = args.split() + if len(args) > 1: + cmd = EVENTROUTER.cmds.get(args[1]) + if cmd: + cmds = {args[1]: cmd} + else: + w.prnt('', 'Command not found: ' + args[1]) + return w.WEECHAT_RC_OK + else: + cmds = EVENTROUTER.cmds + w.prnt('', 'Slack commands:') + + for name, cmd in sorted(cmds.items()): + helptext = (cmd.__doc__ or '').rstrip() + w.prnt('', '{}:{}'.format(name, helptext)) + return w.WEECHAT_RC_OK + + @slack_buffer_required def command_distracting(data, current_buffer, args): channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None) @@ -3850,8 +3874,6 @@ def load_emoji(): def setup_hooks(): - cmds = get_functions_with_prefix("command_") - w.bar_item_new('slack_typing_notice', '(extra)typing_bar_item_cb', '') w.hook_timer(1000, 0, 0, "typing_update_cb", "") @@ -3873,10 +3895,10 @@ def setup_hooks(): '[command] [command options]', # Description of arguments 'Commands:\n' + - '\n'.join(cmds.keys()) + + '\n'.join(sorted(EVENTROUTER.cmds.keys())) + '\nUse /slack help [command] to find out more\n', # Completions - '|'.join(cmds.keys()), + '|'.join(EVENTROUTER.cmds.keys()), # Function name 'slack_command_cb', '') # w.hook_command('me', '', 'stuff', 'stuff2', '', 'me_command_cb', '') -- cgit