comparison bot.py @ 250:5d6ff929e6bc

fixed IRC "mode" event handling Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 23:22:19 +0100
parents 5e65f52be453
children 38dd27098fef
comparison
equal deleted inserted replaced
249:430eb5052e4d 250:5d6ff929e6bc
588 588
589 # Chan events 589 # Chan events
590 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']: 590 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'mode', 'join']:
591 591
592 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname: 592 if event.eventtype() in ['pubmsg', 'action', 'part', 'kick', 'join'] and not source_nickname:
593 self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event', no_debug_add=event_str) 593 self.error(say_levels.debug, 'a source is needed for a '+event.eventtype()+' event'+event_str)
594 return 594 return
595 595
596 if event.eventtype() == 'kick' and len(event.arguments()) == 0: 596 if event.eventtype() in ['kick', 'mode'] and len(event.arguments()) == 0:
597 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) 597 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event'+event_str)
598 return
599
600 if event.eventtype() == 'mode' and len(event.arguments()) < 2:
601 self.error(say_levels.debug, '2 arguments are needed for a '+event.eventtype()+' event'+event_str)
602 return 598 return
603 599
604 chan = event.target().lower() 600 chan = event.target().lower()
605 601
606 bridge = self.get_bridge(irc_room=chan, irc_server=connection.server) 602 bridge = self.get_bridge(irc_room=chan, irc_server=connection.server)
620 # kick handling 616 # kick handling
621 if event.eventtype() == 'kick': 617 if event.eventtype() == 'kick':
622 try: 618 try:
623 kicked = bridge.get_participant(event.arguments()[0]) 619 kicked = bridge.get_participant(event.arguments()[0])
624 except Bridge.NoSuchParticipantException: 620 except Bridge.NoSuchParticipantException:
625 self.error(2, debug_str, debug=True) 621 self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?'+event_str)
626 self.error(say_levels.debug, 'a participant that was not here has been kicked ? WTF ?', no_debug_add=event_str)
627 return 622 return
628 623
629 leave_message = 'kicked by '+nickname 624 leave_message = 'kicked by '+nickname
630 if len(event.arguments()) > 1: 625 if len(event.arguments()) > 1:
631 leave_message += ' with reason: '+event.arguments()[1] 626 leave_message += ' with reason: '+event.arguments()[1]
674 return 669 return
675 670
676 671
677 # Mode event 672 # Mode event
678 if event.eventtype() == 'mode': 673 if event.eventtype() == 'mode':
679 if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: 674 if len(event.arguments()) == 1:
680 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) 675 # chan mode
681 return 676 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for chan "'+event.target()+'"', debug=True)
682 if re.search('\+[^\-]*o', event.arguments()[0]): 677 elif len(event.arguments()) == 2:
683 # bot is channel operator 678 # participant mode
684 bridge.irc_op = True 679 if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]:
685 self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan) 680 self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'" in chan "'+event.target()+'"', debug=True)
686 elif re.search('\-[^\+]*o', event.arguments()[0]): 681 return
687 # bot lost channel operator privileges 682 if re.search('\+[^\-]*o', event.arguments()[0]):
688 if bridge.irc_op: 683 # bot is channel operator
689 self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True) 684 bridge.irc_op = True
690 bridge.irc_op = False 685 self.error(say_levels.notice, 'bot has IRC operator privileges in '+chan)
686 elif re.search('\-[^\+]*o', event.arguments()[0]):
687 # bot lost channel operator privileges
688 if bridge.irc_op:
689 self.error(say_levels.notice, 'bot lost IRC operator privileges in '+chan, send_to_admins=True)
690 bridge.irc_op = False
691 else:
692 # unknown mode
693 self.error(say_levels.debug, 'unknown IRC "mode" event (has 3 arguments):'+event_str)
691 return 694 return
692 695
693 696
694 # Namreply event 697 # Namreply event
695 if event.eventtype() == 'namreply': 698 if event.eventtype() == 'namreply':