aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/test_topic_command.py7
-rw-r--r--wee_slack.py26
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