comparison bot.py @ 225:da8fbaf69242

fixed 'cannotsendtochan' and 'notonchannel' handling, ignore 'inviteonlychan', 'bannedfromchan', 'channelisfull' and 'badchannelkey' (handled via join callbacks) Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 07 Mar 2010 19:01:57 +0100
parents 1a82d5d40d90
children 3c493741e53a
comparison
equal deleted inserted replaced
224:8e6a0b60eed1 225:da8fbaf69242
457 457
458 458
459 # Events we always want to ignore 459 # Events we always want to ignore
460 if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']: 460 if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']:
461 return 461 return
462 if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns']: 462 if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328', 'pubnotice', '042', 'umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns', 'inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']:
463 self.error(1, 'ignoring IRC '+event.eventtype(), debug=True) 463 self.error(1, 'ignoring IRC '+event.eventtype(), debug=True)
464 return 464 return
465 465
466 466
467 nickname = None 467 nickname = None
595 595
596 if handled: 596 if handled:
597 return 597 return
598 598
599 599
600 # Handle bannedfromchan
601 if event.eventtype() == 'bannedfromchan':
602 if len(event.arguments()) < 1:
603 self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event', debug=True)
604 return
605
606 for bridge in self.bridges:
607 if connection.server != bridge.irc_server or event.arguments()[0].lower() != bridge.irc_room:
608 continue
609
610 if event.target() == self.nickname:
611 self.error(say_levels.error, 'the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
612 raise Exception('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
613 else:
614 try:
615 banned = bridge.get_participant(event.target())
616 if banned.irc_connection != 'bannedfromchan':
617 banned.irc_connection = 'bannedfromchan'
618 self.error(2, debug_str, debug=True)
619 bridge.say(say_levels.warning, 'the nickname "'+event.target()+'" is banned from the IRC chan', log=True)
620 else:
621 self.error(1, 'ignoring '+event.eventtype(), debug=True)
622 except Bridge.NoSuchParticipantException:
623 self.error(1, 'no such participant. WTF ?', debug=True)
624 return
625
626 return
627
628
629 if event.eventtype() in ['disconnect', 'kill', 'error']: 600 if event.eventtype() in ['disconnect', 'kill', 'error']:
630 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': 601 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
631 self.error(2, debug_str, debug=True) 602 self.error(2, debug_str, debug=True)
632 else: 603 else:
633 self.error(say_levels.debug, debug_str, send_to_admins=True) 604 self.error(say_levels.debug, debug_str, send_to_admins=True)
634 return 605 return
635 606
636 607
637 if event.eventtype() in ['cannotsendtochan', 'notonchannel', 'inviteonlychan']: 608 # Chan errors
609 if event.eventtype() in ['cannotsendtochan', 'notonchannel']:
638 self.error(2, debug_str, debug=True) 610 self.error(2, debug_str, debug=True)
639 bridges = self.iter_bridges(irc_room=event.arguments()[0], irc_server=connection.server) 611 bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server)
640 if len(bridges) > 1: 612
641 raise Exception, 'more than one bridge for one irc chan, WTF ?' 613 if event.eventtype() == 'cannotsendtochan':
642 bridge = bridges[0] 614 if connection.real_nickname == self.nickname:
643 if connection.real_nickname == self.nickname: 615 bridge._join_irc_failed(event.eventtype())
644 bridge._join_irc_failed(event.eventtype()) 616 else:
645 else: 617 p = bridge.get_participant(connection.real_nickname)
646 p = bridge.get_participant(connection.real_nickname) 618 p._close_irc_connection(event.eventtype())
647 p._close_irc_connection('') 619 p.irc_connection = event.eventtype()
648 p.irc_connection = event.eventtype() 620
621 elif event.eventtype() == 'notonchannel':
622 if connection.real_nickname == self.nickname:
623 bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype())
624 else:
625 p = bridge.get_participant(connection.real_nickname)
626 p.irc_connection.join(bridge.irc_room)
627
649 return 628 return
650 629
651 630
652 # Ignore events not received on bot connection 631 # Ignore events not received on bot connection
653 if connection.real_nickname != self.nickname: 632 if connection.real_nickname != self.nickname: