Added conf.replyWithPrivateNotice and 'notice' command.

This commit is contained in:
Stéphan Kochen 2003-10-20 10:10:46 +00:00
parent b02cdef575
commit e12f69b7a2
6 changed files with 45 additions and 8 deletions

View File

@ -507,6 +507,16 @@ def main():
'addressed but given a non-command?') == 'y':
configVariables['replyWhenNotCommand'] = False
# replyWithPrivateNotice
myPrint("""When a user sends a command to the bot from within a
channel, the bot, by default, also responds to that channel. In some
rather busy channels this might be considered spam, especially if the
command returns several lines in its result. In this case you may want
to notice the user instead.""")
if yn('Would you like the bot to notice replies to users in private'
'when a command is executed in a channel?') == 'y':
configVariables['replyWithPrivateNotice'] = True
myPrint("""Here in supybot-developer world, we really like Python. In
fact, we like it so much we just couldn't do without the ability to
have our bots evaluate arbitrary Python code. Of course, we are aware

View File

@ -371,6 +371,14 @@ class MiscCommands(callbacks.Privmsg):
text = privmsgs.getArgs(args)
irc.reply(msg, text, private=True)
def notice(self, irc, msg, args):
"""<text>
Replies with <text> in a private notice. Use nested commands to your
benefit here.
"""
text = privmsgs.getArgs(args)
irc.reply(msg, text, notice=True)
Class = MiscCommands

View File

@ -98,11 +98,13 @@ def canonicalName(command):
"""
return command.translate(string.ascii, '\t -_').lower()
def reply(msg, s, prefixName=True, private=False):
def reply(msg, s, prefixName=True, private=False, notice=False):
"""Makes a reply to msg with the payload s"""
s = ircutils.safeArgument(s)
if ircutils.isChannel(msg.args[0]) and not private:
if prefixName:
if notice or conf.replyWithPrivateNotice:
m = ircmsgs.notice(msg.nick, s)
elif prefixName:
m = ircmsgs.privmsg(msg.args[0], '%s: %s' % (msg.nick, s))
else:
m = ircmsgs.privmsg(msg.args[0], s)
@ -318,6 +320,7 @@ class IrcObjectProxy:
self.finalEvaled = False
self.action = False
self.private = False
self.notice = False
self.prefixName = True
self.noLengthCheck = False
world.commandsProcessed += 1
@ -390,7 +393,7 @@ class IrcObjectProxy:
self.error(self.msg, debug.exnToString(e))
def reply(self, msg, s, noLengthCheck=False, prefixName=True,
action=False, private=False):
action=False, private=False, notice=False):
"""reply(msg, text) -> replies to msg with text
Keyword arguments:
@ -400,18 +403,21 @@ class IrcObjectProxy:
reply.
action=False: True if the reply should be an action.
private=False: True if the reply should be in private.
notice=False: True if the reply should be noticed when the
bot is configured to do so.
"""
# These use |= or &= based on whether or not they default to True or
# False. Those that default to True use &=; those that default to
# False use |=.
self.action |= action
self.private |= private
self.notice |= notice
self.prefixName &= prefixName
self.noLengthCheck |= noLengthCheck
if self.finalEvaled:
if isinstance(self.irc, self.__class__):
self.irc.reply(msg, s, self.noLengthCheck, self.prefixName,
self.action, self.private)
self.action, self.private, self.notice)
elif self.noLengthCheck:
self.irc.queueMsg(reply(msg, s, self.prefixName))
elif self.action:
@ -448,7 +454,8 @@ class IrcObjectProxy:
if self.private:
self.irc.queueMsg(ircmsgs.privmsg(msg.nick, response))
else:
self.irc.queueMsg(reply(msg, response, self.prefixName))
self.irc.queueMsg(reply(msg, response, self.prefixName,
notice=self.notice))
else:
self.args[self.counter] = s
self.evalArgs()
@ -650,11 +657,12 @@ class IrcObjectProxyRegexp:
private = private or conf.errorReplyPrivate
self.reply(msg, 'Error: ' + s, private=private)
def reply(self, msg, s, prefixName=True, action=False, private=False,):
def reply(self, msg, s, prefixName=True, action=False, private=False,
notice=False):
if action:
self.irc.queueMsg(ircmsgs.action(ircutils.replyTo(msg), s))
else:
self.irc.queueMsg(reply(msg, s, private=private,
self.irc.queueMsg(reply(msg, s, private=private, notice=notice,
prefixName=prefixName))
def __getattr__(self, attr):

View File

@ -92,6 +92,12 @@ allowEval = False
###
replyWhenNotCommand = True
###
# replyWithPrivateNotice: True if replies to a user in a channel should be
# noticed to that user instead of sent to the channel
# itself.
replyWithPrivateNotice = False
###
# requireRegistration: Oftentimes a plugin will want to record who added or
# changed or messed with it last. Supybot's user database

View File

@ -133,6 +133,9 @@ class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation):
m = self.getMsg('private [list]')
self.failIf(ircutils.isChannel(m.args[0]))
def testNotice(self):
m = self.getMsg('notice [list]')
self.assertEqual(m.command, 'NOTICE')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -142,6 +142,8 @@ class FunctionsTestCase(unittest.TestCase):
self.assertEqual(ircmsgs.privmsg(channelMsg.args[0],
'foo'),
callbacks.reply(channelMsg, 'foo', prefixName=False))
self.assertEqual(ircmsgs.notice(nonChannelMsg.nick, 'foo'),
callbacks.reply(channelMsg, 'foo', notice=True))
def testGetCommands(self):
self.assertEqual(callbacks.getCommands(['foo']), ['foo'])