diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-26 22:19:18 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2017-10-08 23:58:49 +0200 |
commit | 4c63a2103635fb7ab8b19dbcbbc8d9df167542d5 (patch) | |
tree | 786c811eb99b9a2236d7f40df3dc3264325e3e35 /wee_slack.py | |
parent | d6fb56faf85dd1abbb8789295c290c162a02067f (diff) | |
download | wee-slack-4c63a2103635fb7ab8b19dbcbbc8d9df167542d5.tar.gz |
refactor: Split topic_command_cb and add tests
Split out the parts of topic_command_cb that's most interesting and
easiest to test into parse_topic_command and add tests for that
function.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/wee_slack.py b/wee_slack.py index 37db0ec..46ad278 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2825,6 +2825,28 @@ def part_command_cb(data, current_buffer, args): return w.WEECHAT_RC_OK_EAT +def parse_topic_command(command): + args = command.split()[1:] + channel_name = None + topic = None + + if args: + if args[0].startswith('#'): + channel_name = args[0][1:] + topic = args[1:] + else: + topic = args + + if topic == []: + topic = None + if topic: + topic = ' '.join(topic) + if topic == '-delete': + topic = '' + + return channel_name, topic + + @slack_buffer_or_ignore def topic_command_cb(data, current_buffer, command): """ @@ -2833,18 +2855,10 @@ def topic_command_cb(data, current_buffer, command): """ data = decode_from_utf8(data) 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 + channel_name, topic = parse_topic_command(command) + team = EVENTROUTER.weechat_controller.buffers[current_buffer].team if channel_name: channel = team.channels.get(team.get_channel_map().get(channel_name)) else: @@ -2854,12 +2868,7 @@ def topic_command_cb(data, current_buffer, command): 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 == []: + if topic is None: w.prnt(channel.channel_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.slack_topic['value'])) else: s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash) |