From 57e894de589dcdf9c7a63f8279105420e0890674 Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 24 May 2010 15:21:58 -0400 Subject: [PATCH] Anonymous: Implement support for allowPrivateTarget config. Closes: Sf#2991515 Signed-off-by: James Vega --- plugins/Anonymous/plugin.py | 48 +++++++++++++++++++++---------------- plugins/Anonymous/test.py | 13 +++++++--- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/plugins/Anonymous/plugin.py b/plugins/Anonymous/plugin.py index 18205306e..9eb95260d 100644 --- a/plugins/Anonymous/plugin.py +++ b/plugins/Anonymous/plugin.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2005, Daniel DiPaolo +# Copyright (c) 2010, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -45,7 +46,7 @@ class Anonymous(callbacks.Plugin): that the user be registered by setting supybot.plugins.Anonymous.requireRegistration. """ - def _preCheck(self, irc, msg, channel): + def _preCheck(self, irc, msg, target, action): if self.registryValue('requireRegistration'): try: _ = ircdb.users.getUser(msg.prefix) @@ -55,35 +56,42 @@ class Anonymous(callbacks.Plugin): 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(format('You must be in %s to %q in there.', - channel, 'say'), Raise=True) - c = ircdb.channels.getChannel(channel) - if c.lobotomized: - irc.error(format('I\'m lobotomized in %s.', channel), Raise=True) - if not c._checkCapability(self.name()): - irc.error('That channel has set its capabilities so as to ' - 'disallow the use of this plugin.', Raise=True) + if irc.isChannel(target): + if self.registryValue('requirePresenceInChannel', target) and \ + msg.nick not in irc.state.channels[target].users: + irc.error(format('You must be in %s to %q in there.', + target, action), Raise=True) + c = ircdb.channels.getChannel(target) + if c.lobotomized: + irc.error(format('I\'m lobotomized in %s.', target), + Raise=True) + if not c._checkCapability(self.name()): + irc.error('That channel has set its capabilities so as to ' + 'disallow the use of this plugin.', Raise=True) + elif action == 'say' and not self.registryValue('allowPrivateTarget'): + irc.error(format('%q cannot be used to send private messages.', + action), + Raise=True) - def say(self, irc, msg, args, channel, text): - """ + def say(self, irc, msg, args, target, text): + """ - Sends to . + Sends to . Can only send to if + supybot.plugins.Anonymous.allowPrivateTarget is True. """ - self._preCheck(irc, msg, channel) - self.log.info('Saying %q in %s due to %s.', - text, channel, msg.prefix) - irc.queueMsg(ircmsgs.privmsg(channel, text)) + self._preCheck(irc, msg, target, 'say') + self.log.info('Saying %q to %s due to %s.', + text, target, msg.prefix) + irc.queueMsg(ircmsgs.privmsg(target, text)) irc.noReply() - say = wrap(say, ['inChannel', 'text']) + say = wrap(say, [first('nick', 'inChannel'), 'text']) def do(self, irc, msg, args, channel, text): """ Performs in . """ - self._preCheck(irc, msg, channel) + self._preCheck(irc, msg, channel, 'do') self.log.info('Performing %q in %s due to %s.', text, channel, msg.prefix) irc.queueMsg(ircmsgs.action(channel, text)) diff --git a/plugins/Anonymous/test.py b/plugins/Anonymous/test.py index 728306348..4d2dd1575 100644 --- a/plugins/Anonymous/test.py +++ b/plugins/Anonymous/test.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2005, Daniel DiPaolo +# Copyright (c) 2010, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -32,14 +33,20 @@ from supybot.test import * class AnonymousTestCase(ChannelPluginTestCase): plugins = ('Anonymous',) def testSay(self): - m = self.assertError('anonymous say %s I love you!' % self.channel) + self.assertError('anonymous say %s I love you!' % self.channel) + self.assertError('anonymous say %s I love you!' % self.nick) + origreg = conf.supybot.plugins.Anonymous.requireRegistration() + origpriv = conf.supybot.plugins.Anonymous.allowPrivateTarget() try: - orig = conf.supybot.plugins.Anonymous.requireRegistration() conf.supybot.plugins.Anonymous.requireRegistration.setValue(False) m = self.assertNotError('anonymous say %s foo!' % self.channel) self.failUnless(m.args[1] == 'foo!') + conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(True) + m = self.assertNotError('anonymous say %s foo!' % self.nick) + self.failUnless(m.args[1] == 'foo!') finally: - conf.supybot.plugins.Anonymous.requireRegistration.setValue(orig) + conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg) + conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(origpriv) def testAction(self): m = self.assertError('anonymous do %s loves you!' % self.channel)