diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-03-29 03:16:08 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-04-19 12:22:17 +0200 |
commit | 856159d8e5ceff5f678ab4d5a8ecb2ca6b972b0a (patch) | |
tree | 8dc0a4d2a844556d7943d7ad592444ae774924f3 | |
parent | 15168752c666d821b55a3074cbab9d6d857af5d6 (diff) | |
download | wee-slack-856159d8e5ceff5f678ab4d5a8ecb2ca6b972b0a.tar.gz |
Support newlines in the /topic command
Fixes #728
-rw-r--r-- | _pytest/test_topic_command.py | 7 | ||||
-rw-r--r-- | wee_slack.py | 26 |
2 files changed, 18 insertions, 15 deletions
diff --git a/_pytest/test_topic_command.py b/_pytest/test_topic_command.py index 5224ab7..79a26d3 100644 --- a/_pytest/test_topic_command.py +++ b/_pytest/test_topic_command.py @@ -19,6 +19,13 @@ def test_parse_topic_with_text(): assert topic == 'some topic text' +def test_parse_topic_with_text_with_newline(): + channel_name, topic = parse_topic_command('/topic some topic text\nsecond line') + + assert channel_name is None + assert topic == 'some topic text\nsecond line' + + def test_parse_topic_with_delete(): channel_name, topic = parse_topic_command('/topic -delete') diff --git a/wee_slack.py b/wee_slack.py index 56e3efa..dc96e2e 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3812,23 +3812,19 @@ def part_command_cb(data, current_buffer, args): def parse_topic_command(command): - args = command.split()[1:] - channel_name = None - topic = None - - if args: - if args[0].startswith('#'): - channel_name = args[0] - topic = args[1:] - else: - topic = args + _, _, args = command.partition(' ') + if args.startswith('#'): + channel_name, _, topic_arg = args.partition(' ') + else: + channel_name = None + topic_arg = args - if topic == []: - topic = None - if topic: - topic = ' '.join(topic) - if topic == '-delete': + if topic_arg == '-delete': topic = '' + elif topic_arg: + topic = topic_arg + else: + topic = None return channel_name, topic |