From e12f69b7a225bceb96e76dde0cb6f59d8724ad80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Mon, 20 Oct 2003 10:10:46 +0000 Subject: [PATCH] Added conf.replyWithPrivateNotice and 'notice' command. --- scripts/supybot-wizard.py | 10 ++++++++++ src/MiscCommands.py | 8 ++++++++ src/callbacks.py | 22 +++++++++++++++------- src/conf.py | 6 ++++++ test/test_MiscCommands.py | 5 ++++- test/test_callbacks.py | 2 ++ 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/scripts/supybot-wizard.py b/scripts/supybot-wizard.py index 944db5d44..3dc4abcbb 100755 --- a/scripts/supybot-wizard.py +++ b/scripts/supybot-wizard.py @@ -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 diff --git a/src/MiscCommands.py b/src/MiscCommands.py index b971478c3..617658802 100755 --- a/src/MiscCommands.py +++ b/src/MiscCommands.py @@ -371,6 +371,14 @@ class MiscCommands(callbacks.Privmsg): text = privmsgs.getArgs(args) irc.reply(msg, text, private=True) + def notice(self, irc, msg, args): + """ + + Replies with in a private notice. Use nested commands to your + benefit here. + """ + text = privmsgs.getArgs(args) + irc.reply(msg, text, notice=True) Class = MiscCommands diff --git a/src/callbacks.py b/src/callbacks.py index 15761bab8..dcaaf3679 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -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): diff --git a/src/conf.py b/src/conf.py index 81996ccc6..ea2dab316 100644 --- a/src/conf.py +++ b/src/conf.py @@ -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 diff --git a/test/test_MiscCommands.py b/test/test_MiscCommands.py index 020242ae3..c2ff72c2f 100644 --- a/test/test_MiscCommands.py +++ b/test/test_MiscCommands.py @@ -132,7 +132,10 @@ class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation): def testPrivate(self): 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: diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 334e4e7bb..7c8e1374d 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -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'])