comparison bot.py @ 219:63289aa1dea7

moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 07 Mar 2010 12:08:29 +0100
parents d527d7b75f56
children 5726a0833537
comparison
equal deleted inserted replaced
218:ca22fdea1c17 219:63289aa1dea7
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']: 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']:
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
468 if event.source() != None: 468 if event.source() != None:
469 if '!' in event.source(): 469 if '!' in event.source():
470 nickname = event.source().split('!')[0] 470 nickname = event.source().split('!')[0]
471 471
472 472
473 # Events that we want to ignore only in some cases
474 if event.eventtype() in ['umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns']:
475 if connection.really_connected == False:
476 if event.target() == connection.nickname:
477 connection.really_connected = True
478 connection._call_nick_callbacks(None)
479 elif len(connection.nick_callbacks) > 0:
480 self.error(3, 'event target ('+event.target()+') and connection nickname ('+connection.nickname+') don\'t match', debug=True)
481 connection._call_nick_callbacks('nicknametoolong', arguments=[len(event.target())])
482 self.error(1, 'ignoring '+event.eventtype(), debug=True)
483 return
484
485
486 # A string representation of the event 473 # A string representation of the event
487 event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments()) 474 event_str = '\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+repr(event.source())+'\ntarget='+repr(event.target())+'\narguments='+repr(event.arguments())
488 debug_str = 'Received IRC event.'+event_str 475 debug_str = 'Received IRC event.'+event_str
489 printed_event = False 476 printed_event = False
490 477
497 484
498 if event.eventtype() in ['quit', 'part'] and nickname == self.nickname: 485 if event.eventtype() in ['quit', 'part'] and nickname == self.nickname:
499 return 486 return
500 487
501 if event.eventtype() in ['quit', 'part', 'nick', 'kick']: 488 if event.eventtype() in ['quit', 'part', 'nick', 'kick']:
502 if connection.get_nickname() != self.nickname: 489 if connection.real_nickname != self.nickname:
503 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) 490 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
504 return 491 return
505 else: 492 else:
506 self.error(2, debug_str, debug=True) 493 self.error(2, debug_str, debug=True)
507 printed_event = True 494 printed_event = True
509 if event.eventtype() == 'kick' and len(event.arguments()) < 1: 496 if event.eventtype() == 'kick' and len(event.arguments()) < 1:
510 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str) 497 self.error(say_levels.debug, 'at least 1 argument is needed for a '+event.eventtype()+' event', no_debug_add=event_str)
511 return 498 return
512 499
513 if event.eventtype() in ['pubmsg', 'action']: 500 if event.eventtype() in ['pubmsg', 'action']:
514 if connection.get_nickname() != self.nickname: 501 if connection.real_nickname != self.nickname:
515 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) 502 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
516 return 503 return
517 if nickname == self.nickname: 504 if nickname == self.nickname:
518 self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True) 505 self.error(1, 'ignoring IRC '+event.eventtype()+' sent by self', debug=True)
519 return 506 return
652 self.error(2, debug_str, debug=True) 639 self.error(2, debug_str, debug=True)
653 bridges = self.iter_bridges(irc_room=event.arguments()[0], irc_server=connection.server) 640 bridges = self.iter_bridges(irc_room=event.arguments()[0], irc_server=connection.server)
654 if len(bridges) > 1: 641 if len(bridges) > 1:
655 raise Exception, 'more than one bridge for one irc chan, WTF ?' 642 raise Exception, 'more than one bridge for one irc chan, WTF ?'
656 bridge = bridges[0] 643 bridge = bridges[0]
657 if connection.get_nickname() == self.nickname: 644 if connection.real_nickname == self.nickname:
658 bridge._join_irc_failed(event.eventtype()) 645 bridge._join_irc_failed(event.eventtype())
659 else: 646 else:
660 p = bridge.get_participant(connection.get_nickname()) 647 p = bridge.get_participant(connection.real_nickname)
661 p._close_irc_connection('') 648 p._close_irc_connection('')
662 p.irc_connection = event.eventtype() 649 p.irc_connection = event.eventtype()
663 return 650 return
664 651
665 652
666 # Ignore events not received on bot connection 653 # Ignore events not received on bot connection
667 if connection.get_nickname() != self.nickname: 654 if connection.real_nickname != self.nickname:
668 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) 655 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True)
669 return 656 return
670 657
671 658
672 # Joining events 659 # Joining events