2010-12-11 00:22:26 -06:00
|
|
|
"""
|
|
|
|
Echo - repeat text
|
|
|
|
Copyright (C) 2010 Brian S. Stephan
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-12-20 10:20:33 -06:00
|
|
|
"""
|
2011-01-07 20:37:24 -06:00
|
|
|
|
2010-12-11 00:22:26 -06:00
|
|
|
from Module import Module
|
|
|
|
|
|
|
|
class Echo(Module):
|
2011-01-06 23:25:46 -06:00
|
|
|
|
|
|
|
"""Repeat provided text."""
|
2010-12-11 00:22:26 -06:00
|
|
|
|
2012-12-20 10:20:33 -06:00
|
|
|
def register_handlers(self):
|
|
|
|
"""Hook handler functions into the IRC library."""
|
|
|
|
|
2012-12-20 10:36:53 -06:00
|
|
|
# register IRC regex handlers
|
2012-12-20 10:20:33 -06:00
|
|
|
self.irc.add_global_regex_handler('pubmsg', r'^!echo\s+(.*)$',
|
|
|
|
self.echo)
|
|
|
|
self.irc.add_global_regex_handler('privmsg', r'^!echo\s+(.*)$',
|
|
|
|
self.echo)
|
|
|
|
|
2012-12-20 10:36:53 -06:00
|
|
|
# register XML-RPC handlers
|
|
|
|
def echo_wrap(msg):
|
|
|
|
"""Get back the sent message.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
msg the message to get returned
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
msg
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self.echo(None, None, None, False, (msg,))
|
|
|
|
self.irc.xmlrpc_register_function(echo_wrap, 'echo')
|
|
|
|
|
2012-12-20 10:20:33 -06:00
|
|
|
def unregister_handlers(self):
|
|
|
|
"""Unhook handler functions from the IRC library."""
|
|
|
|
|
|
|
|
self.irc.remove_global_regex_handler('pubmsg', r'^!echo\s+(.*)$',
|
|
|
|
self.echo)
|
|
|
|
self.irc.remove_global_regex_handler('privmsg', r'^!echo\s+(.*)$',
|
|
|
|
self.echo)
|
|
|
|
|
|
|
|
def echo(self, nick, userhost, event, from_admin, groups):
|
|
|
|
"""Return the message received.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
nick source nickname (unused)
|
|
|
|
userhost source userhost (unused)
|
|
|
|
event IRC event, used in IRC reply, or none for direct call
|
|
|
|
from_admin whether or not the event came from an admin (unused)
|
2012-12-20 14:29:52 -06:00
|
|
|
groups tuple length 1, the message to echo
|
2012-12-20 10:20:33 -06:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = groups[0]
|
|
|
|
self.log.debug("replying with '{0:s}'".format(msg))
|
2011-01-06 23:25:46 -06:00
|
|
|
|
2012-12-20 10:20:33 -06:00
|
|
|
if event:
|
|
|
|
return self.irc.reply(event, msg)
|
|
|
|
else:
|
|
|
|
return msg
|
2010-12-11 00:22:26 -06:00
|
|
|
|
|
|
|
# vi:tabstop=4:expandtab:autoindent
|
|
|
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|