diff --git a/dr_botzo/ircbot/bot.py b/dr_botzo/ircbot/bot.py index 7c18741..a22ef09 100644 --- a/dr_botzo/ircbot/bot.py +++ b/dr_botzo/ircbot/bot.py @@ -16,6 +16,7 @@ import time from django.conf import settings +import irc.buffer import irc.client from irc.connection import Factory from irc.dict import IRCDict @@ -43,6 +44,17 @@ class PrioritizedRegexHandler(collections.namedtuple('Base', ('priority', 'regex return self.priority < other.priority +class LenientServerConnection(irc.client.ServerConnection): + """ + An IRC server connection. + + ServerConnection objects are instantiated by calling the server + method on a Reactor object. + """ + + buffer_class = irc.buffer.LenientDecodingLineBuffer + + class DrReactor(irc.client.Reactor): """Customize the basic IRC library's Reactor with more features.""" @@ -56,6 +68,14 @@ class DrReactor(irc.client.Reactor): on_schedule=on_schedule) 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.