do some small cleanups
This commit is contained in:
parent
3aadde4b71
commit
572ecddceb
@ -1,5 +1,4 @@
|
||||
"""Provide the base IRC client bot which other code can latch onto."""
|
||||
|
||||
import bisect
|
||||
import collections
|
||||
import copy
|
||||
@ -30,7 +29,7 @@ class PrioritizedRegexHandler(collections.namedtuple('Base', ('priority', 'regex
|
||||
"""Regex handler that still uses the normal handler priority stuff."""
|
||||
|
||||
def __lt__(self, other):
|
||||
"""When sorting prioritized handlers, only use the priority"""
|
||||
"""When sorting prioritized handlers, only use the priority."""
|
||||
return self.priority < other.priority
|
||||
|
||||
|
||||
@ -55,6 +54,9 @@ class LenientServerConnection(irc.client.ServerConnection):
|
||||
class DrReactor(irc.client.Reactor):
|
||||
"""Customize the basic IRC library's Reactor with more features."""
|
||||
|
||||
# used by Reactor.server() to initialize
|
||||
connection_class = LenientServerConnection
|
||||
|
||||
def __do_nothing(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@ -63,18 +65,10 @@ class DrReactor(irc.client.Reactor):
|
||||
super(DrReactor, self).__init__(on_connect=on_connect, on_disconnect=on_disconnect)
|
||||
self.regex_handlers = {}
|
||||
|
||||
def server(self):
|
||||
"""Creates and returns a ServerConnection object."""
|
||||
c = LenientServerConnection(self)
|
||||
with self.mutex:
|
||||
self.connections.append(c)
|
||||
return c
|
||||
|
||||
def add_global_regex_handler(self, events, regex, handler, priority=0):
|
||||
"""Adds a global handler function for a specific event type and regex.
|
||||
"""Add a global handler function for a specific event type and regex.
|
||||
|
||||
Arguments:
|
||||
|
||||
events --- Event type(s) (a list of strings).
|
||||
|
||||
handler -- Callback function taking connection and event
|
||||
@ -104,10 +98,9 @@ class DrReactor(irc.client.Reactor):
|
||||
bisect.insort(event_regex_handlers, handler)
|
||||
|
||||
def remove_global_regex_handler(self, events, handler):
|
||||
"""Removes a global regex handler function.
|
||||
"""Remove a global regex handler function.
|
||||
|
||||
Arguments:
|
||||
|
||||
events -- Event type(s) (a list of strings).
|
||||
handler -- Callback function.
|
||||
|
||||
@ -218,8 +211,7 @@ class DrReactor(irc.client.Reactor):
|
||||
if result == "NO MORE":
|
||||
return
|
||||
except Exception as ex:
|
||||
log.error("caught exception!")
|
||||
log.exception(ex)
|
||||
log.exception("caught exception!")
|
||||
connection.privmsg(event.target, str(ex))
|
||||
|
||||
def try_recursion(self, connection, event):
|
||||
|
Loading…
Reference in New Issue
Block a user