Fix for bug about reply.withPrivateNotice overriding stuff.

This commit is contained in:
Jeremy Fincher 2004-08-08 00:41:13 +00:00
parent 16c832bd62
commit 3db50c1a2b
2 changed files with 54 additions and 14 deletions

View File

@ -123,8 +123,8 @@ def canonicalName(command):
command = command[:-1] command = command[:-1]
return command.translate(string.ascii, special).lower() + reAppend return command.translate(string.ascii, special).lower() + reAppend
def reply(msg, s, prefixName=True, private=False, def reply(msg, s, prefixName=True, private=None,
notice=False, to=None, action=False): notice=None, to=None, action=None):
# Ok, let's make the target: # Ok, let's make the target:
target = ircutils.replyTo(msg) target = ircutils.replyTo(msg)
if private: if private:
@ -134,7 +134,7 @@ def reply(msg, s, prefixName=True, private=False,
else: else:
target = msg.nick target = msg.nick
# XXX: User value. # XXX: User value.
if conf.supybot.reply.withNoticeWhenPrivate(): if conf.supybot.reply.withNoticeWhenPrivate() and notice is None:
notice = True notice = True
if to is None: if to is None:
to = msg.nick to = msg.nick
@ -151,8 +151,10 @@ def reply(msg, s, prefixName=True, private=False,
if notice: if notice:
msgmaker = ircmsgs.notice msgmaker = ircmsgs.notice
if conf.supybot.reply.withPrivateNotice(): if conf.supybot.reply.withPrivateNotice():
target = msg.nick if private is None:
msgmaker = ircmsgs.notice target = msg.nick
if notice is None:
msgmaker = ircmsgs.notice
if action: if action:
msgmaker = ircmsgs.action msgmaker = ircmsgs.action
# Finally, we'll return the actual message. # Finally, we'll return the actual message.
@ -467,10 +469,10 @@ class IrcObjectProxy(RichReplyMethods):
def _resetReplyAttributes(self): def _resetReplyAttributes(self):
self.to = None self.to = None
self.action = False self.action = None
self.notice = False self.notice = None
self.private = False self.private = None
self.noLengthCheck = False self.noLengthCheck = None
self.prefixName = conf.supybot.reply.withNickPrefix() self.prefixName = conf.supybot.reply.withNickPrefix()
def evalArgs(self): def evalArgs(self):
@ -571,7 +573,7 @@ class IrcObjectProxy(RichReplyMethods):
self._callCommand(name, command, cb) self._callCommand(name, command, cb)
def reply(self, s, noLengthCheck=False, prefixName=True, def reply(self, s, noLengthCheck=False, prefixName=True,
action=False, private=False, notice=False, to=None, msg=None): action=None, private=None, notice=None, to=None, msg=None):
"""reply(s) -> replies to msg with s """reply(s) -> replies to msg with s
Keyword arguments: Keyword arguments:
@ -593,10 +595,14 @@ class IrcObjectProxy(RichReplyMethods):
'Old code alert: there is no longer a "msg" argument to reply.' 'Old code alert: there is no longer a "msg" argument to reply.'
if msg is None: if msg is None:
msg = self.msg msg = self.msg
self.action = action or self.action if action is not None:
self.notice = notice or self.notice self.action = self.action or action
self.private = private or self.private if notice is not None:
self.to = to or self.to self.notice = self.notice or notice
if private is not None:
self.private = self.private or private
if to is not None:
self.to = self.to or to
# action=True implies noLengthCheck=True and prefixName=False # action=True implies noLengthCheck=True and prefixName=False
self.prefixName = prefixName and self.prefixName and not self.action self.prefixName = prefixName and self.prefixName and not self.action
self.noLengthCheck=noLengthCheck or self.noLengthCheck or self.action self.noLengthCheck=noLengthCheck or self.noLengthCheck or self.action

View File

@ -439,4 +439,38 @@ class RichReplyMethodsTestCase(PluginTestCase):
self.irc.addCallback(self.NoCapability()) self.irc.addCallback(self.NoCapability())
self.assertRegexp('error', 'admin') self.assertRegexp('error', 'admin')
class WithPrivateNoticeTestCase(ChannelPluginTestCase):
plugins = ()
class WithPrivateNotice(callbacks.Privmsg):
def normal(self, irc, msg, args):
irc.reply('should be with private notice')
def explicit(self, irc, msg, args):
irc.reply('should not be with private notice',
private=False, notice=False)
def test(self):
self.irc.addCallback(self.WithPrivateNotice())
# Check normal behavior.
m = self.assertNotError('normal')
self.failIf(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit')
self.failIf(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0]))
# Check abnormal behavior.
original = conf.supybot.reply.withPrivateNotice()
try:
conf.supybot.reply.withPrivateNotice.setValue(True)
m = self.assertNotError('normal')
self.failUnless(m.command == 'NOTICE')
self.failIf(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit')
self.failIf(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0]))
finally:
conf.supybot.reply.withPrivateNotice.setValue(original)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: