use LenientDecodingLineBuffer in bot guts

should make the bot more resilient to clients that send non-unicode text
This commit is contained in:
Brian S. Stephan 2015-06-22 17:43:45 -05:00
parent 0c7b880517
commit e2d4e29750
1 changed files with 20 additions and 0 deletions

View File

@ -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.