def test_get_mentions_anywhere(self): test = 'Hello! This, this testCase is a test.' message = Message(test, self.mock_firefly, self.hostmask) r = message.get_mentions(['casetest', 'TestCase'], message.MENTION_ANYWHERE) self.assertIsNotNone(r) self.assertTupleEqual(r, ('testCase', 'Hello! This, this testCase is a test.', r[2]))
def test_get_mentions_end(self): test = 'Hello! This, this TestCase is a test, TestCase,' message = Message(test, self.mock_firefly, self.hostmask) r = message.get_mentions(['casetest', 'TestCase'], message.MENTION_END) self.assertIsNotNone(r) self.assertTupleEqual(r, ('TestCase', 'Hello! This, this TestCase is a test', r[2])) self.assertEqual(r[2].group('ender'), ',')
def test_get_mentions_start(self): test = 'Testcase: hello! This, this is a test.' message = Message(test, self.mock_firefly, self.hostmask) r = message.get_mentions(['casetest', 'TestCase']) self.assertIsNotNone(r) self.assertTupleEqual(r, ('Testcase', 'hello! This, this is a test.', r[2])) self.assertEqual(r[2].group('separator'), ':')
def privmsg(self, user, channel, message): """ Called when I have a message from a user to me or a channel. @type user: C{str} @param user: Hostmask of the sender. @type channel: C{str} @param channel: Name of the source channel or user nick. @type message: C{str} """ hostmask = Hostmask(user) destination = Destination(self, channel) message = Message(message, destination, hostmask) is_command = False has_reply = False reply_dest = destination groups = set() # Log the message self.server.get_or_create_channel(channel).message_log.add_message(message) # Is the message a command? if message.is_command: self._log.debug('Message registered as a command: %s', repr(message)) is_command = True groups.add('command') command_plugin, command_name, command_args = message.command_parts self._fire_command(command_plugin, command_name, command_args, message) # Is this a private message? if message.destination.is_user: groups.add(None) groups.add('private') reply_dest = hostmask # Have we been mentioned in this message? nicks = self.server.identity.nicks try: nick, raw_message, match = message.get_mentions(nicks) groups.add(None) except TypeError: self._log.debug('Message has no mentions at the beginning') try: nick, raw_message, match = message.get_mentions(nicks, message.MENTION_END) groups.add(None) except TypeError: self._log.debug('Message has no mentions at the end') nick = self.nickname raw_message = message.stripped match = False if message.destination.is_channel: groups.add('public') # Do we have a language response? reply = self.language.get_reply(raw_message, groups=groups) if reply: self._log.debug('Reply matched: %s', reply) has_reply = True self.msg(reply_dest, reply) # Fire global event self._fire_event(irc.on_message, has_reply, is_command, message=message) # Fire custom events if message.destination.is_channel: self.channelMessage(message, has_reply, is_command) elif message.destination.is_user: self.privateMessage(message, has_reply, is_command)