From c998dfbebf1e0e26d21eea29cf3ee556c0ab9494 Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Wed, 2 Feb 2005 04:39:45 +0000 Subject: [PATCH] Moving action,reply,private,notice to new Reply plugin (for real) --- plugins/Misc/plugin.py | 30 -------------- plugins/Misc/test.py | 32 --------------- plugins/Reply/README.txt | 1 + plugins/Reply/__init__.py | 62 ++++++++++++++++++++++++++++ plugins/Reply/config.py | 48 ++++++++++++++++++++++ plugins/Reply/plugin.py | 80 +++++++++++++++++++++++++++++++++++++ plugins/Reply/test.py | 59 +++++++++++++++++++++++++++ plugins/Utilities/plugin.py | 8 ---- setup.py | 1 + 9 files changed, 251 insertions(+), 70 deletions(-) create mode 100644 plugins/Reply/README.txt create mode 100644 plugins/Reply/__init__.py create mode 100644 plugins/Reply/config.py create mode 100644 plugins/Reply/plugin.py create mode 100644 plugins/Reply/test.py diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 1fba83bfd..be19aeea2 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -441,36 +441,6 @@ class Misc(callbacks.Privmsg): irc.reply(s, to=target, private=True) tell = wrap(tell, ['something', 'text']) - def private(self, irc, msg, args, text): - """ - - Replies with in private. Use nested commands to your benefit - here. - """ - irc.reply(text, private=True) - private = wrap(private, ['text']) - - def action(self, irc, msg, args, text): - """ - - Replies with as an action. use nested commands to your benefit - here. - """ - if text: - irc.reply(text, action=True) - else: - raise callbacks.ArgumentError - action = wrap(action, ['text']) - - def notice(self, irc, msg, args, text): - """ - - Replies with in a notice. Use nested commands to your benefit - here. If you want a private notice, nest the private command. - """ - irc.reply(text, notice=True) - notice = wrap(notice, ['text']) - def contributors(self, irc, msg, args, cb, nick): """ [] diff --git a/plugins/Misc/test.py b/plugins/Misc/test.py index f083a29b7..632da16df 100644 --- a/plugins/Misc/test.py +++ b/plugins/Misc/test.py @@ -32,13 +32,6 @@ from supybot.test import * class MiscTestCase(ChannelPluginTestCase): # plugins = ('Misc', 'Utilities', 'Gameknot', 'Anonymous', 'Dict', 'User') plugins = ('Misc', 'Utilities', 'Anonymous', 'Dict', 'User') - def testAction(self): - self.assertAction('action moos', 'moos') - - def testActionDoesNotAllowEmptyString(self): - self.assertHelp('action') - self.assertHelp('action ""') - def testReplyWhenNotCommand(self): try: original = str(conf.supybot.reply.whenNotCommand) @@ -227,22 +220,6 @@ class MiscTestCase(ChannelPluginTestCase): self.assertNotError('more %s' % nick.upper()) self.assertNotError('more %s' % nick.lower()) - 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') - - def testNoticePrivate(self): - m = self.assertNotError('notice [private [list]]') - self.assertEqual(m.command, 'NOTICE') - self.assertEqual(m.args[0], self.nick) - m = self.assertNotError('private [notice [list]]') - self.assertEqual(m.command, 'NOTICE') - self.assertEqual(m.args[0], self.nick) - def testHostmask(self): self.assertResponse('hostmask', self.prefix) self.assertError('@hostmask asdf') @@ -273,14 +250,5 @@ class MiscTestCase(ChannelPluginTestCase): def testRevisionIsCaseInsensitive(self): self.assertNotError('revision misc') - -class MiscNonChannelTestCase(PluginTestCase): - plugins = ('Misc',) - def testAction(self): - self.prefix = 'something!else@somewhere.else' - self.nick = 'something' - m = self.assertAction('action foo', 'foo') - self.failIf(m.args[0] == self.irc.nick) - # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/plugins/Reply/README.txt b/plugins/Reply/README.txt new file mode 100644 index 000000000..d60b47a97 --- /dev/null +++ b/plugins/Reply/README.txt @@ -0,0 +1 @@ +Insert a description of your plugin here, with any notes, etc. about using it. diff --git a/plugins/Reply/__init__.py b/plugins/Reply/__init__.py new file mode 100644 index 000000000..4e00fd4a0 --- /dev/null +++ b/plugins/Reply/__init__.py @@ -0,0 +1,62 @@ +### +# Copyright (c) 2005, Daniel DiPaolo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +""" +This plugin contains various commands which elicit certain types of responses +from the bot. +""" + +import supybot +import supybot.world as world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "%%VERSION%%" + +# XXX Replace this with an appropriate author or supybot.Author instance. +__author__ = supybot.authors.strike + +# This is a dictionary mapping supybot.Author instances to lists of +# contributions. +__contributors__ = {} + +import config +import plugin +reload(plugin) # In case we're being reloaded. +# Add more reloads here if you add third-party modules and want them to be +# reloaded when this plugin is reloaded. Don't forget to import them as well! + +if world.testing: + import test + +Class = plugin.Class +configure = config.configure + + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/plugins/Reply/config.py b/plugins/Reply/config.py new file mode 100644 index 000000000..3deb659a8 --- /dev/null +++ b/plugins/Reply/config.py @@ -0,0 +1,48 @@ +### +# Copyright (c) 2005, Daniel DiPaolo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +import supybot.conf as conf +import supybot.registry as registry + +def configure(advanced): + # This will be called by supybot to configure this module. advanced is + # a bool that specifies whether the user identified himself as an advanced + # user or not. You should effect your configuration by manipulating the + # registry as appropriate. + from supybot.questions import expect, anything, something, yn + conf.registerPlugin('Reply', True) + + +Reply = conf.registerPlugin('Reply') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Reply, 'someConfigVariableName', +# registry.Boolean(False, """Help for someConfigVariableName.""")) + + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78 diff --git a/plugins/Reply/plugin.py b/plugins/Reply/plugin.py new file mode 100644 index 000000000..1759a5d74 --- /dev/null +++ b/plugins/Reply/plugin.py @@ -0,0 +1,80 @@ +### +# Copyright (c) 2005, Daniel DiPaolo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +from supybot.commands import * +import supybot.callbacks as callbacks + + +class Reply(callbacks.Privmsg): + """This plugins contains a few commands that construct various types of + replies. Some bot owners would be wise to not load this plugin because it + can be easily abused. + """ + def private(self, irc, msg, args, text): + """ + + Replies with in private. Use nested commands to your benefit + here. + """ + irc.reply(text, private=True) + private = wrap(private, ['text']) + + def action(self, irc, msg, args, text): + """ + + Replies with as an action. use nested commands to your benefit + here. + """ + if text: + irc.reply(text, action=True) + else: + raise callbacks.ArgumentError + action = wrap(action, ['text']) + + def notice(self, irc, msg, args, text): + """ + + Replies with in a notice. Use nested commands to your benefit + here. If you want a private notice, nest the private command. + """ + irc.reply(text, notice=True) + notice = wrap(notice, ['text']) + + def reply(self, irc, msg, args, text): + """ + + Replies with . Equivalent to the alias, 'echo $nick: $1'. + """ + irc.reply(text, prefixName=True) + reply = wrap(reply, ['text']) + +Class = Reply + + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/plugins/Reply/test.py b/plugins/Reply/test.py new file mode 100644 index 000000000..2ce111cc3 --- /dev/null +++ b/plugins/Reply/test.py @@ -0,0 +1,59 @@ +### +# Copyright (c) 2005, Daniel DiPaolo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +from supybot.test import * +import supybot.ircutils as ircutils + +class ReplyTestCase(ChannelPluginTestCase): + plugins = ('Reply',) + 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') + + def testNoticePrivate(self): + m = self.assertNotError('notice [private [list]]') + self.assertEqual(m.command, 'NOTICE') + self.assertEqual(m.args[0], self.nick) + m = self.assertNotError('private [notice [list]]') + self.assertEqual(m.command, 'NOTICE') + self.assertEqual(m.args[0], self.nick) + +class ReplyNonChannelTestCase(PluginTestCase): + plugins = ('Reply',) + def testAction(self): + self.prefix = 'something!else@somewhere.else' + self.nick = 'something' + m = self.assertAction('action foo', 'foo') + self.failIf(m.args[0] == self.irc.nick) + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/plugins/Utilities/plugin.py b/plugins/Utilities/plugin.py index d6bfad8cf..d2ef5be7e 100644 --- a/plugins/Utilities/plugin.py +++ b/plugins/Utilities/plugin.py @@ -46,14 +46,6 @@ class Utilities(callbacks.Privmsg): pass # Do be careful not to wrap this unless you do any('something'). - def reply(self, irc, msg, args, text): - """ - - Replies with . Equivalent to the alias, 'echo $nick: $1'. - """ - irc.reply(text, prefixName=True) - reply = wrap(reply, ['text']) - def success(self, irc, msg, args, text): """[] diff --git a/setup.py b/setup.py index 7f17bf983..7bb5f2fd7 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,7 @@ plugins = [ 'Misc', 'Owner', 'QuoteGrabs', + 'Reply', 'Scheduler', 'ShrinkUrl', 'Status',