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': 'addressed but given a non-command?') == 'y':
configVariables['replyWhenNotCommand'] = False 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 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 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 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) text = privmsgs.getArgs(args)
irc.reply(msg, text, private=True) 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 Class = MiscCommands

View File

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

View File

@ -92,6 +92,12 @@ allowEval = False
### ###
replyWhenNotCommand = True 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 # requireRegistration: Oftentimes a plugin will want to record who added or
# changed or messed with it last. Supybot's user database # changed or messed with it last. Supybot's user database

View File

@ -132,7 +132,10 @@ class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation):
def testPrivate(self): def testPrivate(self):
m = self.getMsg('private [list]') m = self.getMsg('private [list]')
self.failIf(ircutils.isChannel(m.args[0])) 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: # 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], self.assertEqual(ircmsgs.privmsg(channelMsg.args[0],
'foo'), 'foo'),
callbacks.reply(channelMsg, 'foo', prefixName=False)) callbacks.reply(channelMsg, 'foo', prefixName=False))
self.assertEqual(ircmsgs.notice(nonChannelMsg.nick, 'foo'),
callbacks.reply(channelMsg, 'foo', notice=True))
def testGetCommands(self): def testGetCommands(self):
self.assertEqual(callbacks.getCommands(['foo']), ['foo']) self.assertEqual(callbacks.getCommands(['foo']), ['foo'])