diff options
author | Alex Dills <alex@stechstudios.com> | 2016-10-20 16:36:48 -0400 |
---|---|---|
committer | Tollef Fog Heen <tfheen@err.no> | 2016-10-20 22:36:48 +0200 |
commit | c70db4e01e2cbab2a586b7f9bf72feaaa2991a60 (patch) | |
tree | fe07cd08d8fe79403328aa19f6f7de81d174d842 | |
parent | 1316cbc95a6315a65f090bc2f7c85cce06071001 (diff) | |
download | wee-slack-c70db4e01e2cbab2a586b7f9bf72feaaa2991a60.tar.gz |
Add support for slash commands
Custom slash commands are handled by doing `/slack slash /foo [args…]`
Fixes: #227
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | wee_slack.py | 29 |
2 files changed, 35 insertions, 1 deletions
@@ -12,6 +12,7 @@ A WeeChat native client for Slack.com. Provides supplemental features only avail Features -------- + * **New** Slash commands (including custom ones!) * **New** Upload to slack capabilities! * Emoji reactions! * Edited messages work just like the official clients, where the original message changes and has (edited) appended. @@ -32,7 +33,6 @@ Features * Away/back status handling * Expands/shows metadata for things like tweets/links * Displays edited messages (slack.com irc mode currently doesn't show these) - * *Super fun* debug mode. See what the websocket is saying with `/slack debug` In Development @@ -177,6 +177,11 @@ Upload a file to the current slack buffer: /slack upload [file_path] ``` +Run a Slack slash command. Simply prepend `/slack slash` to what you'd type in the official clients.: +``` +/slack slash /desiredcommand arg1 arg2 arg3 +``` + Debug mode: ``` /slack debug diff --git a/wee_slack.py b/wee_slack.py index f0572dc..1720862 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1308,6 +1308,35 @@ def command_markread(current_buffer, args): servers.find(domain).channels.find(channel).mark_read() +@slack_buffer_required +def command_slash(current_buffer, args): + """ + Support for custom slack commands + /slack slash /customcommand arg1 arg2 arg3 + """ + + server = servers.find(current_domain_name()) + channel = current_buffer_name(short=True) + domain = current_domain_name() + + if args is None: + server.buffer_prnt("Usage: /slack slash /someslashcommand [arguments...].") + return + + split_args = args.split(None, 1) + + command = split_args[0] + text = split_args[1] if len(split_args) > 1 else "" + + if servers.find(domain).channels.find(channel): + channel_identifier = servers.find(domain).channels.find(channel).identifier + + if channel_identifier: + async_slack_api_request(server.domain, server.token, 'chat.command', {'command': command, 'text': text, 'channel': channel_identifier}) + else: + server.buffer_prnt("User or channel not found.") + + def command_flushcache(current_buffer, args): global message_cache message_cache = collections.defaultdict(list) |