comparison bot.py @ 172:64a0e9636ae6

removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Tue, 02 Feb 2010 20:19:50 +0100
parents 489c157d9e82
children d1686164b9e3
comparison
equal deleted inserted replaced
171:489c157d9e82 172:64a0e9636ae6
20 import threading 20 import threading
21 from time import sleep 21 from time import sleep
22 import traceback 22 import traceback
23 import xml.parsers.expat 23 import xml.parsers.expat
24 24
25 from encoding import *
26 import irclib 25 import irclib
27 import muc 26 import muc
28 xmpp = muc.xmpp 27 xmpp = muc.xmpp
29 del muc 28 del muc
30 29
65 def error(self, s, debug=False, send_to_admins=False): 64 def error(self, s, debug=False, send_to_admins=False):
66 """Output an error message.""" 65 """Output an error message."""
67 if send_to_admins == True: 66 if send_to_admins == True:
68 self._send_message_to_admins(s) 67 self._send_message_to_admins(s)
69 if not debug or debug and self.debug: 68 if not debug or debug and self.debug:
70 try: 69 self.error_fd.write(s.encode('utf-8')+"\n")
71 self.error_fd.write(auto_encode(s)+"\n")
72 except EncodingException:
73 self.error_fd.write('Error message cannot be transcoded.\n')
74 70
75 71
76 def _xmpp_loop(self): 72 def _xmpp_loop(self):
77 """[Internal] XMPP infinite loop.""" 73 """[Internal] XMPP infinite loop."""
78 i = 1 74 i = 1
476 self.error('=> Debug: ignoring '+event.eventtype(), debug=True) 472 self.error('=> Debug: ignoring '+event.eventtype(), debug=True)
477 return 473 return
478 474
479 475
480 # A string representation of the event 476 # A string representation of the event
481 event_str = '==> Debug: Received IRC event.\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+auto_decode(event.source().__str__())+'\ntarget='+auto_decode(event.target().__str__())+'\narguments='+auto_decode(event.arguments().__str__()) 477 event_str = '==> Debug: Received IRC event.\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments())
482 478
483 479
484 if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: 480 if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']:
485 if nickname == None: 481 if nickname == None:
486 return 482 return
674 self.xmpp_c.send(xmpp.protocol.Message(to=admin_jid, body=message, typ='chat')) 670 self.xmpp_c.send(xmpp.protocol.Message(to=admin_jid, body=message, typ='chat'))
675 except: 671 except:
676 pass 672 pass
677 673
678 674
679 def new_bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=1): 675 def new_bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=1, irc_charsets=None):
680 """Create a bridge between xmpp_room and irc_room at irc_server.""" 676 """Create a bridge between xmpp_room and irc_room at irc_server."""
681 b = Bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=irc_port, irc_connection_interval=irc_connection_interval) 677 b = Bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=irc_port, irc_connection_interval=irc_connection_interval, irc_charsets=irc_charsets)
682 self.bridges.append(b) 678 self.bridges.append(b)
683 return b 679 return b
684 680
685 681
686 def findBridges(self, str_array): 682 def findBridges(self, str_array):