# -*- coding: utf-8 -*- ### # Copyright (c) 2011, Terence Simpson # 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.utils as utils from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks class Say(callbacks.Plugin): """A plugin to say something when told to""" def doPrivmsg(self, irc, msg): # is this message addressed to us? message = callbacks.addressed(irc.nick, msg) if not message: # it wasn't return # do nothing # here we split off the single-word command into bot_cmd, # and put the rest of the message into message bot_cmd = message.split(None, 1)[0] message = message[len(bot_cmd):].strip() # next we check if the command we got is the one we are listening for if bot_cmd.lower() != 'say': # some other command, so we do nothing return if not message: # the message we got was only one word, we need more irc.error("I need something to say") # reply with an error return # and return # Now we know we were addressed, we know we were given the command we # were looking for 'say', and we have the message to say. all that's # left to do, is actually say the message irc.reply(message) Class = Say # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: