diff --git a/plugins/Anonymous.py b/plugins/Anonymous.py index 0f7fa41ad..5f3225720 100644 --- a/plugins/Anonymous.py +++ b/plugins/Anonymous.py @@ -65,47 +65,55 @@ conf.registerGlobalValue(conf.supybot.plugins.Anonymous, 'requireRegistration', conf.registerGlobalValue(conf.supybot.plugins.Anonymous, 'requireCapability', registry.String('', """Determines what capability (if any) the bot should require people trying to use this plugin to have.""")) - class Anonymous(callbacks.Privmsg): private = True + def _preCheck(self, irc, msg, channel): + if self.registryValue('requireRegistration'): + try: + _ = ircdb.users.getUser(msg.prefix) + except KeyError: + irc.errorNotRegistered(Raise=True) + if channel not in irc.state.channels: + irc.error('I\'m not in %s, chances are that I can\'t say anything ' + 'in there.' % channel, Raise=True) + capability = self.registryValue('requireCapability') + if capability: + if not ircdb.checkCapability(msg.prefix, capability): + irc.errorNoCapability(capability, Raise=True) + if self.registryValue('requirePresenceInChannel', channel) and \ + msg.nick not in irc.state.channels[channel].users: + irc.error('You must be in %s to "say" in there.' % channel, + Raise=True) + c = ircdb.channels.getChannel(channel) + if c.lobotomized: + irc.error('I\'m lobotomized in %s.' % channel, Raise=True) + if not c.checkCapability(self.__class__.__name__): + irc.error('That channel has set its capabilities so as to ' + 'disallow the use of this plugin.', Raise=True) + def say(self, irc, msg, args): """ Sends to . """ (channel, text) = privmsgs.getArgs(args, required=2) - if self.registryValue('requireRegistration'): - try: - _ = ircdb.users.getUser(msg.prefix) - except KeyError: - irc.errorNotRegistered() - return - if channel not in irc.state.channels: - irc.error('I\'m not in %s, chances are that I can\'t say anything ' - 'in there.' % channel) - return - capability = self.registryValue('requireCapability') - if capability: - if not ircdb.checkCapability(msg.prefix, capability): - irc.errorNoCapability(capability) - return - if self.registryValue('requirePresenceInChannel', channel) and \ - msg.nick not in irc.state.channels[channel].users: - irc.error('You must be in %s to "say" in there.' % channel) - return - c = ircdb.channels.getChannel(channel) - if c.lobotomized: - irc.error('I\'m lobotomized in %s.' % channel) - return - if not c.checkCapability(self.__class__.__name__): - irc.error('That channel has set its capabilities so as to ' - 'disallow the use of this plugin.') - return + self._preCheck(irc, msg, channel) self.log.info('Saying %r in %s due to %s.', text, channel, msg.prefix) irc.queueMsg(ircmsgs.privmsg(channel, text)) + def action(self, irc, msg, args): + """ + + Performs in . + """ + (channel, action) = privmsgs.getArgs(args, required=2) + self._preCheck(irc, msg, channel) + self.log.info('Performing %r in %s due to %s.', + action, channel, msg.prefix) + irc.queueMsg(ircmsgs.action(channel, action)) + Class = Anonymous diff --git a/test/test_Anonymous.py b/test/test_Anonymous.py index 99286b7ed..7e2c00aa4 100644 --- a/test/test_Anonymous.py +++ b/test/test_Anonymous.py @@ -43,6 +43,17 @@ class AnonymousTestCase(ChannelPluginTestCase): finally: conf.supybot.plugins.Anonymous.requireRegistration.setValue(orig) + def testAction(self): + m = self.assertError('anonymous action %s loves you!' % self.channel) + try: + orig = conf.supybot.plugins.Anonymous.requireRegistration() + conf.supybot.plugins.Anonymous.requireRegistration.setValue(False) + m = self.assertNotError('anonymous action %s loves you!'%self.channel) + self.failUnless(m.args == ircmsgs.action(self.channel, + 'loves you!').args) + finally: + conf.supybot.plugins.Anonymous.requireRegistration.setValue(orig) + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: