From 67411ad0bc73d3eb01aa07b126f47f806446c649 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 15 May 2015 18:22:13 -0500 Subject: [PATCH] echo: a simple echo plugin --- dr_botzo/ircbot/ircplugins/echo.py | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dr_botzo/ircbot/ircplugins/echo.py diff --git a/dr_botzo/ircbot/ircplugins/echo.py b/dr_botzo/ircbot/ircplugins/echo.py new file mode 100644 index 0000000..e97f4df --- /dev/null +++ b/dr_botzo/ircbot/ircplugins/echo.py @@ -0,0 +1,37 @@ +import logging + +from ircbot.lib import Plugin, reply_destination_for_event + + +log = logging.getLogger('ircbot.lib') + + +class Echo(Plugin): + + """Have IRC commands to do IRC things (join channels, quit, etc.).""" + + def start(self): + """Set up the handlers.""" + + self.connection.reactor.add_global_regex_handler('pubmsg', r'^!echo\s+(.*)$', + getattr(self, 'handle_echo'), -20) + self.connection.reactor.add_global_regex_handler('privmsg', r'^!echo\s+(.*)$', + getattr(self, 'handle_echo'), -20) + + super(Echo, self).start() + + def stop(self): + """Tear down handlers.""" + + self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_echo')) + self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_echo')) + + super(Echo, self).stop() + + def handle_echo(self, connection, event, match): + """Handle the echo command... by echoing.""" + + return self.bot.reply(event, match.group(1)) + + +plugin = Echo