From 08d08d537ea734e1c6d611373c0593fadfeff41b Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 20 Dec 2012 10:36:53 -0600 Subject: [PATCH] Echo: wrap echo() for the XML-RPC server this serves as a good example of how to reuse code for the XML-RPC interface. we wrap it for convenience, so that all that needs to be supplied to the web service method is the message to echo. of course, other modules can wrap things how they feel the need to, even adding authentication, i guess, if they wanted note that it doesn't unregister the XML-RPC method. for starters, i didn't add an unregister to DrBotIRC, so it can't, and secondly, it looks like reregistering overwrites the old one. this hasn't been extensively tested but that's what i'm seeing --- modules/Echo.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/Echo.py b/modules/Echo.py index ddf44bc..6b0eeb4 100644 --- a/modules/Echo.py +++ b/modules/Echo.py @@ -26,11 +26,27 @@ class Echo(Module): def register_handlers(self): """Hook handler functions into the IRC library.""" + # register IRC regex handlers self.irc.add_global_regex_handler('pubmsg', r'^!echo\s+(.*)$', self.echo) self.irc.add_global_regex_handler('privmsg', r'^!echo\s+(.*)$', self.echo) + # 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') + def unregister_handlers(self): """Unhook handler functions from the IRC library."""