예제 #1
0
def dispatch_msg_handler_with_bot_message(self, category, msg):
    responded = False
    if 'text' in msg:
        text = msg['text']
    else:
        text = msg['attachments'][0]['text']
    for func, args in self._plugins.get_plugins(category, text):
        if func:
            responded = True
            try:
                func(Message(self._client, msg), *args)
            except Exception:
                logger.exception(
                    'failed to handle message %s with plugin "%s"', text,
                    func.__name__)
                reply = u'[{}] I had a problem handling "{}"\n'.format(
                    func.__name__, text)
                tb = u'```\n{}\n```'.format(traceback.format_exc())
                if self._errors_to:
                    self._client.rtm_send_message(msg['channel'], reply)
                    self._client.rtm_send_message(self._errors_to,
                                                  u'{}\n{}'.format(reply, tb))
                else:
                    self._client.rtm_send_message(msg['channel'],
                                                  u'{}\n{}'.format(reply, tb))
    return responded
예제 #2
0
def fake_message(client: SlackClient, text: str, *, channel: str) -> Message:
    data = {"text": text, "channel": channel}
    return Message(client, data)
예제 #3
0
def get_message(text=None, channel='channelid'):
    message = Message(None, {'channel': channel, 'text': text})
    message.send_webapi = MagicMock()
    return message