def privmsg(self, user, channel, message): user = self.parse_nick(user) message = message.strip() logger.debug('[<--] %s/%s - %s', channel, user, message) # When we get a priv msg, the channel is our current nick, so we need to # respond to the user that is talking to us channel = channel if self.is_public_channel(channel) else user # Some things should go first try: channel, user, message = registry.preprocess( self, channel, user, message) except (TypeError, ValueError): pass # if not message.has_response: responses = registry.process(self, channel, user, message) if responses: self.msg(channel, '\n'.join(responses)) # Update last message self.last_message[channel][user] = message
def test_process_returns_unicode(self): plugin = Mock() plugin.process.return_value = ['foo', 'bar', self.snowman] with patch.object(registry, 'prioritized') as prio: prio.return_value = [plugin] responses = registry.process('', '', '', '') assert all(map(lambda x: isinstance(x, unicode), responses))
def test_process_ignores_exception(self): settings.PLUGIN_FIRST_RESPONDER_ONLY = True things = [Mock(), Mock()] # Make the middle one raise things[0].process.side_effect = Exception things[1].process.return_value = 'foo' with patch.object(registry, 'prioritized') as prio: prio.return_value = things response = registry.process(None, '#bots', 'me', 'foobar') assert response == [u'foo']
def test_process_returns_all_responses(self): settings.PLUGIN_FIRST_RESPONDER_ONLY = False things = [Mock(), Mock(), Mock()] # Make the middle one raise things[0].process.return_value = ['foo', 'bar', None] things[1].process.return_value = self.snowman things[2].process.return_value = 'baz' with patch.object(registry, 'prioritized') as prio: prio.return_value = things response = registry.process(None, '#bots', 'me', 'foobar') assert response == [u'foo', u'bar', self.snowman, u'baz']
def test_process_stops_when_async(self): things = [Mock(), Mock(), Mock()] # Make the middle one raise things[0].process.return_value = None things[1].process.side_effect = ResponseNotReady things[2].process.return_value = None with patch.object(registry, 'prioritized') as prio: prio.return_value = things assert [] == registry.process(None, '#bots', 'me', 'foobar') assert things[1].process.called assert not things[2].process.called
def test_process_returns_first_response(self): settings.PLUGIN_FIRST_RESPONDER_ONLY = True things = [Mock(), Mock(), Mock()] # Make the middle one raise things[0].process.return_value = ['foo', 'bar', None] things[1].process.return_value = self.snowman things[2].process.return_value = 'baz' with patch.object(registry, 'prioritized') as prio: prio.return_value = things response = registry.process(None, '#bots', 'me', 'foobar') assert response == [u'foo', u'bar']
def privmsg(self, user, channel, message): user = self.parse_nick(user) message = message.strip() logger.debug('[<--] %s/%s - %s', channel, user, message) # When we get a priv msg, the channel is our current nick, so we need to # respond to the user that is talking to us channel = channel if self.is_public_channel(channel) else user # Some things should go first try: channel, user, message = registry.preprocess(self, channel, user, message) except (TypeError, ValueError): pass # if not message.has_response: responses = registry.process(self, channel, user, message) if responses: self.msg(channel, '\n'.join(responses)) # Update last message self.last_message[channel][user] = message