aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorAlex Dills <alex@stechstudios.com>2016-10-20 16:36:48 -0400
committerTollef Fog Heen <tfheen@err.no>2016-10-20 22:36:48 +0200
commitc70db4e01e2cbab2a586b7f9bf72feaaa2991a60 (patch)
treefe07cd08d8fe79403328aa19f6f7de81d174d842 /wee_slack.py
parent1316cbc95a6315a65f090bc2f7c85cce06071001 (diff)
downloadwee-slack-c70db4e01e2cbab2a586b7f9bf72feaaa2991a60.tar.gz
Add support for slash commands
Custom slash commands are handled by doing `/slack slash /foo [args…]` Fixes: #227
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py29
1 files changed, 29 insertions, 0 deletions
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)