Mercurial > xib
comparison bot.py @ 187:594f570f4657
handle IRC mode event
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 20 Feb 2010 18:35:23 +0100 |
parents | 70a54da14e63 |
children | bd185885d4ca |
comparison
equal
deleted
inserted
replaced
186:70a54da14e63 | 187:594f570f4657 |
---|---|
486 else: | 486 else: |
487 self.error(2, debug_str, debug=True) | 487 self.error(2, debug_str, debug=True) |
488 printed_event = True | 488 printed_event = True |
489 | 489 |
490 if event.eventtype() == 'kick' and len(event.arguments()) < 1: | 490 if event.eventtype() == 'kick' and len(event.arguments()) < 1: |
491 self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event') | 491 self.error(1, 'at least 1 argument is needed for a '+event.eventtype()+' event', debug=True) |
492 return | 492 return |
493 | 493 |
494 if event.eventtype() in ['pubmsg', 'action']: | 494 if event.eventtype() in ['pubmsg', 'action']: |
495 if connection.get_nickname() != self.nickname: | 495 if connection.get_nickname() != self.nickname: |
496 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) | 496 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) |
617 return | 617 return |
618 | 618 |
619 return | 619 return |
620 | 620 |
621 | 621 |
622 # Joining events | |
623 if event.eventtype() in ['namreply', 'join']: | |
624 if connection.get_nickname() != self.nickname: | |
625 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) | |
626 return | |
627 | |
628 if event.eventtype() == 'namreply': | |
629 for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): | |
630 for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): | |
631 if nickname == '' or nickname == self.nickname: | |
632 continue | |
633 bridge.addParticipant('irc', nickname) | |
634 return | |
635 elif event.eventtype() == 'join': | |
636 bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) | |
637 if len(bridges) == 0: | |
638 self.error(2, debug_str, debug=True) | |
639 self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) | |
640 return | |
641 for bridge in bridges: | |
642 bridge.addParticipant('irc', nickname, irc_id=event.source()) | |
643 return | |
644 | |
645 | |
646 if event.eventtype() in ['disconnect', 'kill', 'error']: | 622 if event.eventtype() in ['disconnect', 'kill', 'error']: |
647 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': | 623 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': |
648 self.error(2, debug_str, debug=True) | 624 self.error(2, debug_str, debug=True) |
649 else: | 625 else: |
650 self.error(2, debug_str, send_to_admins=True) | 626 self.error(2, debug_str, send_to_admins=True) |
661 bridge._join_irc_failed() | 637 bridge._join_irc_failed() |
662 else: | 638 else: |
663 p = bridge.getParticipant(connection.get_nickname()) | 639 p = bridge.getParticipant(connection.get_nickname()) |
664 p._close_irc_connection('') | 640 p._close_irc_connection('') |
665 p.irc_connection = error | 641 p.irc_connection = error |
642 return | |
643 | |
644 | |
645 # Ignore events not received on bot connection | |
646 if connection.get_nickname() != self.nickname: | |
647 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) | |
648 return | |
649 | |
650 | |
651 # Joining events | |
652 if event.eventtype() in ['namreply', 'join']: | |
653 if event.eventtype() == 'namreply': | |
654 for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): | |
655 for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): | |
656 if nickname == '' or nickname == self.nickname: | |
657 continue | |
658 bridge.addParticipant('irc', nickname) | |
659 return | |
660 elif event.eventtype() == 'join': | |
661 bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) | |
662 if len(bridges) == 0: | |
663 self.error(2, debug_str, debug=True) | |
664 self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) | |
665 return | |
666 for bridge in bridges: | |
667 bridge.addParticipant('irc', nickname, irc_id=event.source()) | |
668 return | |
669 | |
670 | |
671 # Mode event | |
672 if event.eventtype() == 'mode': | |
673 if len(event.arguments()) < 2: | |
674 self.error(2, debug_str, debug=True) | |
675 self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) | |
676 return | |
677 if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: | |
678 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) | |
679 return | |
680 self.error(2, debug_str, debug=True) | |
681 bridges = self.getBridges(irc_room=event.target(), irc_server=connection.server) | |
682 if len(bridges) > 1: | |
683 raise Exception, 'more than one bridge for one irc chan, WTF ?' | |
684 bridge = bridges[0] | |
685 if re.search('\+[^\-]*o', event.arguments()[0]): | |
686 # bot is channel operator | |
687 bridge.irc_op = True | |
688 self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) | |
689 elif re.search('\-[^\+]*o', event.arguments()[0]): | |
690 # bot lost channel operator privileges | |
691 if bridge.irc_op: | |
692 self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) | |
693 bridge.irc_op = False | |
666 return | 694 return |
667 | 695 |
668 | 696 |
669 # Unhandled events | 697 # Unhandled events |
670 if not printed_event: | 698 if not printed_event: |