Anonymous: Implement support for allowPrivateTarget config.

Closes: Sf#2991515

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
(cherry picked from commit 57e894de58)
This commit is contained in:
James Vega 2010-05-24 15:21:58 -04:00
parent e9d55d4bbd
commit 246e09cc99
2 changed files with 38 additions and 23 deletions

View File

@ -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):
"""<channel> <text>
def say(self, irc, msg, args, target, text):
"""<channel|nick> <text>
Sends <text> to <channel>.
Sends <text> to <channel|nick>. Can only send to <nick> 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):
"""<channel> <action>
Performs <action> in <channel>.
"""
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))

View File

@ -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)