From 53caf2b94b9275badf4b919e5f9ace3b5b2a1092 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 15 May 2015 22:21:15 -0500 Subject: [PATCH] reference handlers directly rather than w/getattr mostly just picking a convention --- dr_botzo/ircbot/ircplugins/echo.py | 4 ++-- dr_botzo/ircbot/ircplugins/ircmgmt.py | 12 ++++++------ dr_botzo/markov/ircplugin.py | 15 ++++++++------- dr_botzo/weather/ircplugin.py | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/dr_botzo/ircbot/ircplugins/echo.py b/dr_botzo/ircbot/ircplugins/echo.py index de3312e..d4a5680 100644 --- a/dr_botzo/ircbot/ircplugins/echo.py +++ b/dr_botzo/ircbot/ircplugins/echo.py @@ -14,14 +14,14 @@ class Echo(Plugin): """Set up the handlers.""" self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!echo\s+(.*)$', - getattr(self, 'handle_echo'), -20) + self.handle_echo, -20) super(Echo, self).start() def stop(self): """Tear down handlers.""" - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_echo')) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_echo) super(Echo, self).stop() diff --git a/dr_botzo/ircbot/ircplugins/ircmgmt.py b/dr_botzo/ircbot/ircplugins/ircmgmt.py index 3c045cc..24fa130 100644 --- a/dr_botzo/ircbot/ircplugins/ircmgmt.py +++ b/dr_botzo/ircbot/ircplugins/ircmgmt.py @@ -15,20 +15,20 @@ class ChannelManagement(Plugin): """Set up the handlers.""" self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!join\s+([\S]+)', - getattr(self, 'handle_join'), -20) + self.handle_join, -20) self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!part\s+([\S]+)', - getattr(self, 'handle_part'), -20) + self.handle_part, -20) self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!quit\s*(.*)', - getattr(self, 'handle_quit'), -20) + self.handle_quit, -20) super(ChannelManagement, self).start() def stop(self): """Tear down handlers.""" - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_join')) - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_part')) - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_quit')) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_join) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_part) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_quit) super(ChannelManagement, self).stop() diff --git a/dr_botzo/markov/ircplugin.py b/dr_botzo/markov/ircplugin.py index 192ffe7..24d2b93 100644 --- a/dr_botzo/markov/ircplugin.py +++ b/dr_botzo/markov/ircplugin.py @@ -17,21 +17,22 @@ class Markov(Plugin): def start(self): """Set up the handlers.""" - self.connection.add_global_handler('pubmsg', getattr(self, 'handle_chatter'), -20) - self.connection.add_global_handler('privmsg', getattr(self, 'handle_chatter'), -20) + self.connection.add_global_handler('pubmsg', self.handle_chatter, -20) + self.connection.add_global_handler('privmsg', self.handle_chatter, -20) - self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!markov\s+reply(\s+min=(\d+))?(\s+max=(\d+))?(\s+(.*)$|$)', - getattr(self, 'handle_reply'), -20) + self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], + r'^!markov\s+reply(\s+min=(\d+))?(\s+max=(\d+))?(\s+(.*)$|$)', + self.handle_reply, -20) super(Markov, self).start() def stop(self): """Tear down handlers.""" - self.connection.remove_global_handler('pubmsg', getattr(self, 'handle_chatter')) - self.connection.remove_global_handler('privmsg', getattr(self, 'handle_chatter')) + self.connection.remove_global_handler('pubmsg', self.handle_chatter) + self.connection.remove_global_handler('privmsg', self.handle_chatter) - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_reply')) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_reply) super(Markov, self).stop() diff --git a/dr_botzo/weather/ircplugin.py b/dr_botzo/weather/ircplugin.py index 77be484..226b674 100644 --- a/dr_botzo/weather/ircplugin.py +++ b/dr_botzo/weather/ircplugin.py @@ -16,14 +16,14 @@ class Weather(Plugin): """Set up the handlers.""" self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!weather\s+(.*)$', - getattr(self, 'handle_weather'), -20) + self.handle_weather, -20) super(Weather, self).start() def stop(self): """Tear down handlers.""" - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_weather')) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_weather) super(Weather, self).stop()