From a629f51328be80e76f255c329624eda8f3503d59 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 9 Jul 2014 21:03:26 -0400 Subject: [PATCH] Anonymous: Move "say $nick" functionality to new tell command Allowing Anonymous.say to send a message to either a nick or an (implicit) channel through the use of first('nick', 'inChannel') changed the behavior of the command by making it impossible for 'inChannel' to take effect. This meant that any previous users of the command that expected "say some text" to send "some text" to the current channel would instead try to send "text" to the user "some". Depending on the value of conf.plugins.Anonymous.allowPrivateTarget, this would result in either an error or a strange message to a random user. Creating a new tell command solves this issue as Anonymous.channel now goes back to its simple 'inChannel' wrapper. Signed-off-by: James McCoy --- plugins/Anonymous/plugin.py | 23 ++++++++++++++++++----- plugins/Anonymous/test.py | 16 ++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/plugins/Anonymous/plugin.py b/plugins/Anonymous/plugin.py index 7715cfafc..748014b72 100644 --- a/plugins/Anonymous/plugin.py +++ b/plugins/Anonymous/plugin.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2005, Daniel DiPaolo -# Copyright (c) 2010, James McCoy +# Copyright (c) 2014, James McCoy # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -74,17 +74,30 @@ class Anonymous(callbacks.Plugin): Raise=True) def say(self, irc, msg, args, target, text): - """ + """ - Sends to . Can only send to if + Sends to . Can only send to if supybot.plugins.Anonymous.allowPrivateTarget is True. """ self._preCheck(irc, msg, target, 'say') - self.log.info('Saying %q to %s due to %s.', + self.log.info('Saying %q in %s due to %s.', text, target, msg.prefix) irc.queueMsg(ircmsgs.privmsg(target, text)) irc.noReply() - say = wrap(say, [first('nick', 'inChannel'), 'text']) + say = wrap(say, ['inChannel', 'text']) + + def tell(self, irc, msg, args, target, text): + """ + + Sends to . Can only be used if + supybot.plugins.Anonymous.allowPrivateTarget is True. + """ + self._preCheck(irc, msg, target, 'tell') + self.log.info('Telling %q to %s due to %s.', + text, target, msg.prefix) + irc.queueMsg(ircmsgs.privmsg(target, text)) + irc.noReply() + tell = wrap(tell, ['nick', 'text']) def do(self, irc, msg, args, channel, text): """ diff --git a/plugins/Anonymous/test.py b/plugins/Anonymous/test.py index 96a570853..4f9713496 100644 --- a/plugins/Anonymous/test.py +++ b/plugins/Anonymous/test.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2005, Daniel DiPaolo -# Copyright (c) 2010, James McCoy +# Copyright (c) 2014, James McCoy # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -34,15 +34,23 @@ class AnonymousTestCase(ChannelPluginTestCase): plugins = ('Anonymous',) def testSay(self): 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: conf.supybot.plugins.Anonymous.requireRegistration.setValue(False) m = self.assertNotError('anonymous say %s foo!' % self.channel) self.failUnless(m.args[1] == 'foo!') + finally: + conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg) + + def testTell(self): + self.assertError('anonymous tell %s I love you!' % self.nick) + origreg = conf.supybot.plugins.Anonymous.requireRegistration() + origpriv = conf.supybot.plugins.Anonymous.allowPrivateTarget() + try: + conf.supybot.plugins.Anonymous.requireRegistration.setValue(False) + self.assertError('anonymous tell %s foo!' % self.channel) conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(True) - m = self.assertNotError('anonymous say %s foo!' % self.nick) + m = self.assertNotError('anonymous tell %s foo!' % self.nick) self.failUnless(m.args[1] == 'foo!') finally: conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg)