diff -r e24793fae424 -r 1b734faab67a irc.py --- a/irc.py Tue Aug 11 19:12:30 2015 +0300 +++ b/irc.py Sun Aug 16 10:59:22 2015 +0300 @@ -31,10 +31,11 @@ import socket import sys import re -import modulecore as ModuleCore import traceback import time import datetime + +import modulecore from configfile import Config import bt as Bt import hgpoll as HgPoll @@ -124,10 +125,7 @@ def write (self, utfdata): try: - if sys.version_info < (3, 0): - self.send_buffer.append (utfdata.decode("utf-8","ignore").encode("ascii","ignore")) - else: - self.send_buffer.append (utfdata) + self.send_buffer.append (utfdata) except UnicodeEncodeError: pass @@ -150,30 +148,24 @@ if self.verbose: print ("[%s] [%s] <- %s" % (get_timestamp(), self.name, line)) - if sys.version_info >= (3, 0): - self.send (bytes (line + '\n', 'UTF-8')) - else: - self.send (line + '\n') + self.send (bytes (line + '\n', 'UTF-8')) time.sleep (0.25) self.send_buffer = [] def handle_read (self): lines = self.recv (4096).splitlines() for line in lines: - try: - line = line.decode ('utf-8', 'ignore') - - if sys.version_info < (3, 0): - line = line.encode ('ascii', 'ignore') - except UnicodeDecodeError: - continue + line = line.decode ('utf-8', 'ignore') if self.verbose: print ("[%s] [%s] -> %s" % (get_timestamp(), self.name, line)) if line[:len('PING :')] == ('PING :'): self.write ("PONG :%s" % line[len('PING :'):]) - self.send_all_now() # pings must be responded to immediately! + + # Pings must be responded to immediately, otherwise command/event/etc processing may + # delay the pong sending enough for the bot to be disconnected over a timeout. + self.send_all_now() else: words = line.split(" ") if len(words) >= 2: @@ -238,13 +230,13 @@ return if channel != self.mynick: - ModuleCore.call_hook (bot=self, hookname='chanmsg', channel=channel, sender=sender, + modulecore.call_hook (bot=self, hookname='chanmsg', channel=channel, sender=sender, ident=user, host=host, message=message, replyto=replyto) else: - ModuleCore.call_hook (bot=self, hookname='querymsg', sender=sender, ident=user, + modulecore.call_hook (bot=self, hookname='querymsg', sender=sender, ident=user, host=host, message=message, replyto=replyto) - ModuleCore.call_hook (bot=self, hookname='privmsg', target=channel, sender=sender, + modulecore.call_hook (bot=self, hookname='privmsg', target=channel, sender=sender, ident=user, host=host, message=message, replyto=replyto) Bt.process_message (self, line, replyto) @@ -276,10 +268,10 @@ 'replyto': replyto, 'cmdname': command, 'message': message} try: - ModuleCore.call_command (self, **kvargs) + modulecore.call_command (self, **kvargs) return - except ModuleCore.CommandError as e: - lines = str (e).split ('\n') + except modulecore.CommandError as e: + lines = str (e).splitlines() self.privmsg (replyto, 'error: %s' % lines[0]) for line in lines[1:]: