ircbot: list to remove_global_regex_handler
same as previous commit, inverse of add_, for convenience
This commit is contained in:
parent
134c02dc59
commit
903a8f5c80
@ -77,24 +77,30 @@ class DrReactor(irc.client.Reactor):
|
||||
event_regex_handlers = self.regex_handlers.setdefault(event, [])
|
||||
bisect.insort(event_regex_handlers, handler)
|
||||
|
||||
def remove_global_regex_handler(self, event, handler):
|
||||
def remove_global_regex_handler(self, events, handler):
|
||||
"""Removes a global regex handler function.
|
||||
|
||||
Arguments:
|
||||
|
||||
event -- Event type (a string).
|
||||
events -- Event type(s) (a list of strings).
|
||||
handler -- Callback function.
|
||||
|
||||
Returns 1 on success, otherwise 0.
|
||||
"""
|
||||
|
||||
with self.mutex:
|
||||
if not event in self.regex_handlers:
|
||||
return 0
|
||||
for h in self.regex_handlers[event]:
|
||||
if handler == h.callback:
|
||||
self.regex_handlers[event].remove(h)
|
||||
return 1
|
||||
ret = 1
|
||||
|
||||
if type(events) != list:
|
||||
events = [events]
|
||||
|
||||
for event in events:
|
||||
with self.mutex:
|
||||
if not event in self.regex_handlers:
|
||||
ret = 0
|
||||
for h in self.regex_handlers[event]:
|
||||
if handler == h.callback:
|
||||
self.regex_handlers[event].remove(h)
|
||||
return ret
|
||||
|
||||
def _handle_event(self, connection, event):
|
||||
"""Handle an Event event incoming on ServerConnection connection.
|
||||
|
@ -21,8 +21,7 @@ class Echo(Plugin):
|
||||
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'))
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_echo'))
|
||||
|
||||
super(Echo, self).stop()
|
||||
|
||||
|
@ -16,10 +16,8 @@ class ChannelManagement(Plugin):
|
||||
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!join\s+([\S]+)',
|
||||
getattr(self, 'handle_join'), -20)
|
||||
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!part\s+([\S]+)',
|
||||
getattr(self, 'handle_part'), -20)
|
||||
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!quit\s*(.*)',
|
||||
getattr(self, 'handle_quit'), -20)
|
||||
|
||||
@ -28,14 +26,9 @@ class ChannelManagement(Plugin):
|
||||
def stop(self):
|
||||
"""Tear down handlers."""
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_join'))
|
||||
self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_join'))
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_part'))
|
||||
self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_part'))
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_quit'))
|
||||
self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_quit'))
|
||||
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'))
|
||||
|
||||
super(ChannelManagement, self).stop()
|
||||
|
||||
|
@ -31,8 +31,7 @@ class Markov(Plugin):
|
||||
self.connection.remove_global_handler('pubmsg', getattr(self, 'handle_chatter'))
|
||||
self.connection.remove_global_handler('privmsg', getattr(self, 'handle_chatter'))
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_reply'))
|
||||
self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_reply'))
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_reply'))
|
||||
|
||||
super(Markov, self).stop()
|
||||
|
||||
|
@ -23,8 +23,7 @@ class Weather(Plugin):
|
||||
def stop(self):
|
||||
"""Tear down handlers."""
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler('pubmsg', getattr(self, 'handle_weather'))
|
||||
self.connection.reactor.remove_global_regex_handler('privmsg', getattr(self, 'handle_weather'))
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], getattr(self, 'handle_weather'))
|
||||
|
||||
super(Weather, self).stop()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user