Mercurial > xib
comparison bot.py @ 193:c2a8586e64b5
handle IRC inviteonlychan event, improved error messages
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 21 Feb 2010 15:38:42 +0100 |
parents | 6db99e458168 |
children | e4ceefab8ba5 |
comparison
equal
deleted
inserted
replaced
192:12fa9bb73b1d | 193:c2a8586e64b5 |
---|---|
165 else: | 165 else: |
166 r = 'None given' | 166 r = 'None given' |
167 | 167 |
168 # room has been destroyed, stop the bridge | 168 # room has been destroyed, stop the bridge |
169 self.error(say_levels.error, 'The MUC room of the bridge '+str(bridge)+' has been destroyed with reason "'+r+'", stopping the bridge', send_to_admins=True) | 169 self.error(say_levels.error, 'The MUC room of the bridge '+str(bridge)+' has been destroyed with reason "'+r+'", stopping the bridge', send_to_admins=True) |
170 bridge.stop(message='The MUC room of the bridge has been destroyed with reason "'+r+'", stopping the bridge') | 170 bridge.stop(message='The MUC room has been destroyed with reason "'+r+'", stopping the bridge') |
171 | 171 |
172 else: | 172 else: |
173 # presence comes from a participant of the muc | 173 # presence comes from a participant of the muc |
174 | 174 |
175 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') | 175 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') |
415 self.restart() | 415 self.restart() |
416 elif err == 'forbidden': | 416 elif err == 'forbidden': |
417 # we don't have the permission to speak | 417 # we don't have the permission to speak |
418 # let's remove the bridge and tell admins | 418 # let's remove the bridge and tell admins |
419 self.error(say_levels.error, 'Not allowed to speak on the XMPP MUC of bridge '+str(b)+', stopping it', send_to_admins=True) | 419 self.error(say_levels.error, 'Not allowed to speak on the XMPP MUC of bridge '+str(b)+', stopping it', send_to_admins=True) |
420 b.stop(message='Not allowed to speak on the XMPP MUC, stopping bridge.') | 420 b.stop(message='Not allowed to speak on the XMPP MUC, stopping the bridge') |
421 else: | 421 else: |
422 self.error(2, 'recevied unknown error message\n'+message.__str__(fancy=1), debug=True) | 422 self.error(2, 'recevied unknown error message\n'+message.__str__(fancy=1), debug=True) |
423 return | 423 return |
424 | 424 |
425 self.error(2, 'recevied unknown error message\n'+message.__str__(fancy=1), debug=True) | 425 self.error(2, 'recevied unknown error message\n'+message.__str__(fancy=1), debug=True) |
625 else: | 625 else: |
626 self.error(say_levels.debug, debug_str, send_to_admins=True) | 626 self.error(say_levels.debug, debug_str, send_to_admins=True) |
627 return | 627 return |
628 | 628 |
629 | 629 |
630 if event.eventtype() in ['cannotsendtochan', 'notonchannel']: | 630 if event.eventtype() in ['cannotsendtochan', 'notonchannel', 'inviteonlychan']: |
631 self.error(2, debug_str, debug=True) | 631 self.error(2, debug_str, debug=True) |
632 bridges = self.getBridges(irc_room=event.arguments()[0], irc_server=connection.server) | 632 bridges = self.getBridges(irc_room=event.arguments()[0], irc_server=connection.server) |
633 if len(bridges) > 1: | 633 if len(bridges) > 1: |
634 raise Exception, 'more than one bridge for one irc chan, WTF ?' | 634 raise Exception, 'more than one bridge for one irc chan, WTF ?' |
635 bridge = bridges[0] | 635 bridge = bridges[0] |
636 if connection.get_nickname() == self.nickname: | 636 if connection.get_nickname() == self.nickname: |
637 bridge._join_irc_failed() | 637 bridge._join_irc_failed(event.eventtype()) |
638 else: | 638 else: |
639 p = bridge.getParticipant(connection.get_nickname()) | 639 p = bridge.getParticipant(connection.get_nickname()) |
640 p._close_irc_connection('') | 640 p._close_irc_connection('') |
641 p.irc_connection = error | 641 p.irc_connection = error |
642 return | 642 return |
830 else: | 830 else: |
831 c.lock.release() | 831 c.lock.release() |
832 self.error(3, 'XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True) | 832 self.error(3, 'XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True) |
833 | 833 |
834 | 834 |
835 def removeBridge(self, bridge, message='Removing bridge'): | 835 def removeBridge(self, bridge, message='Removing bridge', log=True): |
836 self.bridges.remove(bridge) | 836 self.bridges.remove(bridge) |
837 bridge.stop(message) | 837 bridge.stop(message=message, log=log) |
838 | 838 |
839 | 839 |
840 def respond(self, message, participant=None, bot_admin=False): | 840 def respond(self, message, participant=None, bot_admin=False): |
841 if isinstance(participant, Participant): | 841 if isinstance(participant, Participant): |
842 bridge = participant.bridge | 842 bridge = participant.bridge |
849 | 849 |
850 | 850 |
851 def restart(self): | 851 def restart(self): |
852 # Stop the bridges | 852 # Stop the bridges |
853 for b in self.bridges: | 853 for b in self.bridges: |
854 b.stop(message='Restarting bot') | 854 b.stop(message='Restarting bot', log=False) |
855 | 855 |
856 # Reopen the bot's XMPP connection | 856 # Reopen the bot's XMPP connection |
857 self.reopen_xmpp_connection(self.xmpp_c) | 857 self.reopen_xmpp_connection(self.xmpp_c) |
858 | 858 |
859 # Restart the bridges | 859 # Restart the bridges |
877 if not hasattr(b, 'reconnecting'): | 877 if not hasattr(b, 'reconnecting'): |
878 leave_message += 'will try to recreate the bridge in '+str(delay)+' seconds' | 878 leave_message += 'will try to recreate the bridge in '+str(delay)+' seconds' |
879 b.reconnecting = True | 879 b.reconnecting = True |
880 self.irc.execute_delayed(delay, b.init2) | 880 self.irc.execute_delayed(delay, b.init2) |
881 | 881 |
882 b.stop(message=leave_message) | 882 b.stop(message=leave_message, log=False) |
883 | 883 |
884 self.error(error[0], error[1], send_to_admins=True) | 884 self.error(error[0], error[1], send_to_admins=True) |
885 | 885 |
886 | 886 |
887 def stop(self, message='Stopping bot'): | 887 def stop(self, message='Stopping bot'): |
888 self.error(-1, message, send_to_admins=True) | |
888 for bridge in self.bridges: | 889 for bridge in self.bridges: |
889 bridge.stop(message=message) | 890 bridge.stop(message=message, log=False) |
890 | 891 |
891 | 892 |
892 def __del__(self): | 893 def __del__(self): |
893 for bridge in self.bridges: | 894 for bridge in self.bridges: |
894 self.removeBridge(bridge, message='Stopping bot') | 895 self.removeBridge(bridge, message='Stopping bot', log=False) |
895 self.halt = True | 896 self.halt = True |