diff options
author | Ryan Huber <rhuber@gmail.com> | 2015-11-23 22:20:02 -0800 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2015-11-23 22:20:02 -0800 |
commit | 9e0db5b827768d2b406787b609f400343b8929f6 (patch) | |
tree | ca3ca477c968c7aa21cc092a7502d577a978d79e /wee_slack.py | |
parent | e37a5db7812b92e1dbd9210be9c21ae93066803a (diff) | |
parent | 589758a790dd05cd564790091e1dec2256b5a668 (diff) | |
download | wee-slack-9e0db5b827768d2b406787b609f400343b8929f6.tar.gz |
Merge pull request #128 from rawdigits/58_change_topics
add code to do changes of topic.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py index 5af9cca..c665d35 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1197,6 +1197,40 @@ def command_openweb(current_buffer, args): w.buffer_set(channel_buffer, "title", data["topic"]) return w.WEECHAT_RC_OK +def topic_command_cb(data, current_buffer, args): + if command_topic(current_buffer, args.split(None, 1)[1]): + return w.WEECHAT_RC_OK_EAT + else: + return w.WEECHAT_RC_OK + +def command_topic(current_buffer, args): + """ + Change the topic of a channel + /slack topic [<channel>] [<topic>|-delete] + """ + server = servers.find(current_domain_name()) + if server: + arrrrgs = args.split(None, 1) + if arrrrgs[0].startswith('#'): + channel = server.channels.find(arrrrgs[0]) + topic = arrrrgs[1] + else: + channel = server.channels.find(current_buffer) + topic = args + + if channel: + if topic == "-delete": + async_slack_api_request(server.domain, server.token, 'channels.setTopic', {"channel": channel.identifier, "topic": ""}) + else: + async_slack_api_request(server.domain, server.token, 'channels.setTopic', {"channel": channel.identifier, "topic": topic}) + return True + else: + return False + else: + return False + + + def slack_websocket_cb(server, fd): try: data = servers.find(server).ws.recv() @@ -2110,6 +2144,7 @@ if __name__ == "__main__": w.hook_command_run('/join', 'join_command_cb', '') w.hook_command_run('/part', 'part_command_cb', '') w.hook_command_run('/leave', 'part_command_cb', '') + w.hook_command_run('/topic', 'topic_command_cb', '') w.hook_command_run("/input complete_next", "complete_next_cb", "") w.hook_completion("nicks", "complete @-nicks for slack", "nick_completion_cb", "") |