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."""
|
"""Provide the base IRC client bot which other code can latch onto."""
|
||||||
|
|
||||||
import bisect
|
import bisect
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
@ -30,7 +29,7 @@ class PrioritizedRegexHandler(collections.namedtuple('Base', ('priority', 'regex
|
|||||||
"""Regex handler that still uses the normal handler priority stuff."""
|
"""Regex handler that still uses the normal handler priority stuff."""
|
||||||
|
|
||||||
def __lt__(self, other):
|
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
|
return self.priority < other.priority
|
||||||
|
|
||||||
|
|
||||||
@ -55,6 +54,9 @@ class LenientServerConnection(irc.client.ServerConnection):
|
|||||||
class DrReactor(irc.client.Reactor):
|
class DrReactor(irc.client.Reactor):
|
||||||
"""Customize the basic IRC library's Reactor with more features."""
|
"""Customize the basic IRC library's Reactor with more features."""
|
||||||
|
|
||||||
|
# used by Reactor.server() to initialize
|
||||||
|
connection_class = LenientServerConnection
|
||||||
|
|
||||||
def __do_nothing(*args, **kwargs):
|
def __do_nothing(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -63,18 +65,10 @@ class DrReactor(irc.client.Reactor):
|
|||||||
super(DrReactor, self).__init__(on_connect=on_connect, on_disconnect=on_disconnect)
|
super(DrReactor, self).__init__(on_connect=on_connect, on_disconnect=on_disconnect)
|
||||||
self.regex_handlers = {}
|
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):
|
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:
|
Arguments:
|
||||||
|
|
||||||
events --- Event type(s) (a list of strings).
|
events --- Event type(s) (a list of strings).
|
||||||
|
|
||||||
handler -- Callback function taking connection and event
|
handler -- Callback function taking connection and event
|
||||||
@ -104,10 +98,9 @@ class DrReactor(irc.client.Reactor):
|
|||||||
bisect.insort(event_regex_handlers, handler)
|
bisect.insort(event_regex_handlers, handler)
|
||||||
|
|
||||||
def remove_global_regex_handler(self, events, handler):
|
def remove_global_regex_handler(self, events, handler):
|
||||||
"""Removes a global regex handler function.
|
"""Remove a global regex handler function.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
events -- Event type(s) (a list of strings).
|
events -- Event type(s) (a list of strings).
|
||||||
handler -- Callback function.
|
handler -- Callback function.
|
||||||
|
|
||||||
@ -218,8 +211,7 @@ class DrReactor(irc.client.Reactor):
|
|||||||
if result == "NO MORE":
|
if result == "NO MORE":
|
||||||
return
|
return
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.error("caught exception!")
|
log.exception("caught exception!")
|
||||||
log.exception(ex)
|
|
||||||
connection.privmsg(event.target, str(ex))
|
connection.privmsg(event.target, str(ex))
|
||||||
|
|
||||||
def try_recursion(self, connection, event):
|
def try_recursion(self, connection, event):
|
||||||
|
Loading…
Reference in New Issue
Block a user