mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
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:
parent
e9d55d4bbd
commit
246e09cc99
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2005, Daniel DiPaolo
|
# Copyright (c) 2005, Daniel DiPaolo
|
||||||
|
# Copyright (c) 2010, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# 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
|
that the user be registered by setting
|
||||||
supybot.plugins.Anonymous.requireRegistration.
|
supybot.plugins.Anonymous.requireRegistration.
|
||||||
"""
|
"""
|
||||||
def _preCheck(self, irc, msg, channel):
|
def _preCheck(self, irc, msg, target, action):
|
||||||
if self.registryValue('requireRegistration'):
|
if self.registryValue('requireRegistration'):
|
||||||
try:
|
try:
|
||||||
_ = ircdb.users.getUser(msg.prefix)
|
_ = ircdb.users.getUser(msg.prefix)
|
||||||
@ -55,35 +56,42 @@ class Anonymous(callbacks.Plugin):
|
|||||||
if capability:
|
if capability:
|
||||||
if not ircdb.checkCapability(msg.prefix, capability):
|
if not ircdb.checkCapability(msg.prefix, capability):
|
||||||
irc.errorNoCapability(capability, Raise=True)
|
irc.errorNoCapability(capability, Raise=True)
|
||||||
if self.registryValue('requirePresenceInChannel', channel) and \
|
if irc.isChannel(target):
|
||||||
msg.nick not in irc.state.channels[channel].users:
|
if self.registryValue('requirePresenceInChannel', target) and \
|
||||||
irc.error(format('You must be in %s to %q in there.',
|
msg.nick not in irc.state.channels[target].users:
|
||||||
channel, 'say'), Raise=True)
|
irc.error(format('You must be in %s to %q in there.',
|
||||||
c = ircdb.channels.getChannel(channel)
|
target, action), Raise=True)
|
||||||
if c.lobotomized:
|
c = ircdb.channels.getChannel(target)
|
||||||
irc.error(format('I\'m lobotomized in %s.', channel), Raise=True)
|
if c.lobotomized:
|
||||||
if not c._checkCapability(self.name()):
|
irc.error(format('I\'m lobotomized in %s.', target),
|
||||||
irc.error('That channel has set its capabilities so as to '
|
Raise=True)
|
||||||
'disallow the use of this plugin.', 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):
|
||||||
"""<channel> <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._preCheck(irc, msg, target, 'say')
|
||||||
self.log.info('Saying %q in %s due to %s.',
|
self.log.info('Saying %q to %s due to %s.',
|
||||||
text, channel, msg.prefix)
|
text, target, msg.prefix)
|
||||||
irc.queueMsg(ircmsgs.privmsg(channel, text))
|
irc.queueMsg(ircmsgs.privmsg(target, text))
|
||||||
irc.noReply()
|
irc.noReply()
|
||||||
say = wrap(say, ['inChannel', 'text'])
|
say = wrap(say, [first('nick', 'inChannel'), 'text'])
|
||||||
|
|
||||||
def do(self, irc, msg, args, channel, text):
|
def do(self, irc, msg, args, channel, text):
|
||||||
"""<channel> <action>
|
"""<channel> <action>
|
||||||
|
|
||||||
Performs <action> in <channel>.
|
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.',
|
self.log.info('Performing %q in %s due to %s.',
|
||||||
text, channel, msg.prefix)
|
text, channel, msg.prefix)
|
||||||
irc.queueMsg(ircmsgs.action(channel, text))
|
irc.queueMsg(ircmsgs.action(channel, text))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2005, Daniel DiPaolo
|
# Copyright (c) 2005, Daniel DiPaolo
|
||||||
|
# Copyright (c) 2010, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -32,14 +33,20 @@ from supybot.test import *
|
|||||||
class AnonymousTestCase(ChannelPluginTestCase):
|
class AnonymousTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('Anonymous',)
|
plugins = ('Anonymous',)
|
||||||
def testSay(self):
|
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:
|
try:
|
||||||
orig = conf.supybot.plugins.Anonymous.requireRegistration()
|
|
||||||
conf.supybot.plugins.Anonymous.requireRegistration.setValue(False)
|
conf.supybot.plugins.Anonymous.requireRegistration.setValue(False)
|
||||||
m = self.assertNotError('anonymous say %s foo!'%self.channel)
|
m = self.assertNotError('anonymous say %s foo!'%self.channel)
|
||||||
self.failUnless(m.args[1] == 'foo!')
|
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:
|
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):
|
def testAction(self):
|
||||||
m = self.assertError('anonymous do %s loves you!' % self.channel)
|
m = self.assertError('anonymous do %s loves you!' % self.channel)
|
||||||
|
Loading…
Reference in New Issue
Block a user