diff --git a/slackbot/dispatcher.py b/slackbot/dispatcher.py index 7cfcc41b..0722e507 100644 --- a/slackbot/dispatcher.py +++ b/slackbot/dispatcher.py @@ -1,4 +1,4 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- import logging import re @@ -82,7 +82,7 @@ def filter_text(self, msg): else: m = AT_MESSAGE_MATCHER.match(text) if m: - msg['text'] = m.groups(2)[1] + msg['text'] = m.group(2) return msg def loop(self): diff --git a/tests/functional/driver.py b/tests/functional/driver.py index 8566deff..e7884b4e 100644 --- a/tests/functional/driver.py +++ b/tests/functional/driver.py @@ -53,13 +53,18 @@ def _wait_for_bot_presense(self, online): else: raise AssertionError('test bot is still %s' % ('offline' if online else 'online')) - def send_direct_message(self, msg): - self._send_message_to_bot(self.dm_chan, msg) - - def _send_channel_message(self, chan, msg, tobot=True, colon=True): + def _format_message(self, msg, tobot=True, colon=True): colon = ':' if colon else '' if tobot: msg = '<@%s>%s %s' % (self.testbot_userid, colon, msg) + return msg + + def send_direct_message(self, msg, tobot=True, colon=True): + msg = self._format_message(msg, tobot, colon) + self._send_message_to_bot(self.dm_chan, msg) + + def _send_channel_message(self, chan, msg, tobot=True, colon=True): + msg = self._format_message(msg, tobot, colon) self._send_message_to_bot(chan, msg) def send_channel_message(self, msg, tobot=True, colon=True): diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py index 2c1603ea..115ddd03 100644 --- a/tests/functional/test_functional.py +++ b/tests/functional/test_functional.py @@ -70,6 +70,12 @@ def test_bot_respond_to_simple_message_multiple_plugins(driver): driver.send_direct_message('hello_formatting hello') driver.wait_for_bot_direct_messages({'hello sender!', '_hello_ sender!'}) +def test_bot_direct_message_with_at_prefix(driver): + driver.send_direct_message('hello', tobot=True) + driver.wait_for_bot_direct_message('hello sender!') + driver.send_direct_message('hello', tobot=True, colon=False) + driver.wait_for_bot_direct_message('hello sender!') + def test_bot_default_reply(driver): driver.send_direct_message('youdontunderstandthiscommand do you') driver.wait_for_bot_direct_message('.*You can ask me.*')