comparison bot.py @ 238:a6c37733357a

some more fixes for Bot._irc_event_handler Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 10:58:31 +0100
parents 8acbfda313b9
children 9c039594435d
comparison
equal deleted inserted replaced
237:71c23e30cd6c 238:a6c37733357a
583 583
584 584
585 # Chan events 585 # Chan events
586 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: 586 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']:
587 587
588 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick'] and not source_nickname: 588 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname:
589 self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) 589 self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str)
590 return 590 return
591 591
592 if event.eventtype() == 'kick' and len(event.arguments()) == 0: 592 if event.eventtype() == 'kick' and len(event.arguments()) == 0:
593 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) 593 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str)
594 return 594 return
595 595
596 bridge = self.get_bridge(irc_room=event.target().lower(), irc_server=connection.server) 596 if event.eventtype() == 'mode' and len(event.arguments()) < 2:
597 self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str)
598 return
599
600 chan = event.target().lower()
601
602 bridge = self.get_bridge(irc_room=chan, irc_server=connection.server)
597 603
598 try: 604 try:
599 from_ = bridge.get_participant(source_nickname) 605 from_ = bridge.get_participant(source_nickname)
600 except Bridge.NoSuchParticipantException: 606 except Bridge.NoSuchParticipantException:
601 from_ = None 607 from_ = None
638 644
639 645
640 # Part event 646 # Part event
641 if event.eventtype() == 'part': 647 if event.eventtype() == 'part':
642 if not from_: 648 if not from_:
643 self.error(say_levels.debug, 'a participant that wasn\'t here left:\n'+event_str) 649 self.error(say_levels.debug, 'a participant that wasn\'t here left:'+event_str)
644 return 650 return
645 if len(event.arguments()) > 0: 651 if len(event.arguments()) > 0:
646 leave_message = event.arguments()[0] 652 leave_message = event.arguments()[0]
647 else: 653 else:
648 leave_message = 'Left channel.' 654 leave_message = 'Left channel.'
664 return 670 return
665 671
666 672
667 # Mode event 673 # Mode event
668 if event.eventtype() == 'mode': 674 if event.eventtype() == 'mode':
669 if len(event.arguments()) < 2:
670 self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event\n'+event_str)
671 return
672 if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: 675 if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]:
673 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) 676 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True)
674 return 677 return
675 bridge = self.get_bridge(irc_room=event.target(), irc_server=connection.server)
676 if re.search('\+[^\-]*o', event.arguments()[0]): 678 if re.search('\+[^\-]*o', event.arguments()[0]):
677 # bot is channel operator 679 # bot is channel operator
678 bridge.irc_op = True 680 bridge.irc_op = True
679 self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) 681 self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan)
680 elif re.search('\-[^\+]*o', event.arguments()[0]): 682 elif re.search('\-[^\+]*o', event.arguments()[0]):
681 # bot lost channel operator privileges 683 # bot lost channel operator privileges
682 if bridge.irc_op: 684 if bridge.irc_op:
683 self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) 685 self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True)
684 bridge.irc_op = False 686 bridge.irc_op = False
685 return 687 return
686 688
687 689
688 # Namreply event 690 # Namreply event