aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-09-25 23:32:10 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-09-25 23:49:22 +0200
commitd6fb56faf85dd1abbb8789295c290c162a02067f (patch)
tree3d217b9d1f05e74c51b1eecd4357f464137406dd /wee_slack.py
parent2f43d1b6466c74e8774e2833214f847eb559f15a (diff)
downloadwee-slack-d6fb56faf85dd1abbb8789295c290c162a02067f.tar.gz
fix: Make /topic behave the same way as on IRC
This refactors the topic command, and makes it behave the same way as it does on IRC. The fixes include: - `/topic` prints the topic instead of clearing it - `/topic #channel` prints the topic for that channel in that channels buffer instead of setting the topic to #channel - `/topic #channel [...]` for a channel that doesn't exist gives a proper error message The patch also removes some unused code, refactors the logic and removes the `/slack topic` command, since using `/topic` should suffice. The reason it returs WEECHAT_RC_OK_EAT when the channel isn't found, is so weechat doesn't print an error message such as: irc: command "topic" must be executed on irc buffer (server or channel) Fixes #405
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py67
1 files changed, 32 insertions, 35 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 90b56ac..37db0ec 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2826,48 +2826,45 @@ def part_command_cb(data, current_buffer, args):
@slack_buffer_or_ignore
-def topic_command_cb(data, current_buffer, args):
- n = len(args.split())
- if n < 2:
- channel = channels.find(current_buffer)
- if channel:
- w.prnt(current_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.topic))
- return w.WEECHAT_RC_OK_EAT
- elif command_topic(data, current_buffer, args.split(None, 1)[1]):
- return w.WEECHAT_RC_OK_EAT
- else:
- return w.WEECHAT_RC_ERROR
-
-
-@slack_buffer_required
-def command_topic(data, current_buffer, args):
+def topic_command_cb(data, current_buffer, command):
"""
Change the topic of a channel
- /slack topic [<channel>] [<topic>|-delete]
+ /topic [<channel>] [<topic>|-delete]
"""
data = decode_from_utf8(data)
- args = decode_from_utf8(args)
- e = EVENTROUTER
- team = e.weechat_controller.buffers[current_buffer].team
- # server = servers.find(current_domain_name())
- args = args.split(' ')
- if len(args) > 2 and args[1].startswith('#'):
- cmap = team.get_channel_map()
- channel_name = args[1][1:]
- channel = team.channels[cmap[channel_name]]
- topic = " ".join(args[2:])
+ command = decode_from_utf8(command)
+ team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
+
+ args = command.split()[1:]
+ channel_name = None
+ topic = []
+ if args:
+ if args[0].startswith('#'):
+ channel_name = args[0][1:]
+ topic = args[1:]
+ else:
+ topic = args
+
+ if channel_name:
+ channel = team.channels.get(team.get_channel_map().get(channel_name))
else:
- channel = e.weechat_controller.buffers[current_buffer]
- topic = " ".join(args[1:])
+ channel = EVENTROUTER.weechat_controller.buffers[current_buffer]
- if channel:
- if topic == "-delete":
- topic = ''
- s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash)
- EVENTROUTER.receive(s)
+ if not channel:
+ w.prnt(team.channel_buffer, "#{}: No such channel".format(channel_name))
return w.WEECHAT_RC_OK_EAT
+
+ if topic:
+ topic = ' '.join(topic)
+ if topic == '-delete':
+ topic = ''
+
+ if topic == []:
+ w.prnt(channel.channel_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.slack_topic['value']))
else:
- return w.WEECHAT_RC_ERROR_EAT
+ s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash)
+ EVENTROUTER.receive(s)
+ return w.WEECHAT_RC_OK_EAT
@slack_buffer_or_ignore
@@ -3267,7 +3264,7 @@ def setup_hooks():
w.hook_command_run('/join', 'command_talk', '')
w.hook_command_run('/part', 'part_command_cb', '')
w.hook_command_run('/leave', 'part_command_cb', '')
- w.hook_command_run('/topic', 'command_topic', '')
+ w.hook_command_run('/topic', 'topic_command_cb', '')
w.hook_command_run('/thread', 'thread_command_callback', '')
w.hook_command_run('/reply', 'thread_command_callback', '')
w.hook_command_run('/rehistory', 'rehistory_command_callback', '')