comparison bot.py @ 242:60645c505f11

ignore IRC server-wide events not received on bot connection Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 18:12:17 +0100
parents 9c039594435d
children c9652650d5b5
comparison
equal deleted inserted replaced
241:9c039594435d 242:60645c505f11
512 512
513 # he isn't, send an error 513 # he isn't, send an error
514 connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in') 514 connection.privmsg(source_nickname, 'XIB error: you cannot send a private message to an XMPP user if you are not in one of the chans he is in')
515 515
516 516
517 # Connection errors
518 if event.eventtype() in ['disconnect', 'kill', 'error']:
519 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
520 self.error(2, debug_str, debug=True)
521 else:
522 self.error(say_levels.debug, debug_str, send_to_admins=True)
523 return
524
525
526 # Chan errors
527 if event.eventtype() in ['cannotsendtochan', 'notonchannel']:
528 self.error(2, debug_str, debug=True)
529
530 bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server)
531
532 if event.eventtype() == 'cannotsendtochan':
533 if connection.nickname == self.nickname:
534 bridge._join_irc_failed(event.eventtype())
535 else:
536 p = bridge.get_participant(connection.nickname)
537 p._close_irc_connection(event.eventtype())
538 p.irc_connection = event.eventtype()
539
540 elif event.eventtype() == 'notonchannel':
541 if connection.nickname == self.nickname:
542 bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype())
543 else:
544 p = bridge.get_participant(connection.nickname)
545 p.irc_connection.join(bridge.irc_room)
546
547 return
548
549
550 # Ignore events not received on bot connection
551 if connection.nickname != self.nickname:
552 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True)
553 return
554
555
517 # Server events 556 # Server events
518 if event.eventtype() in ['quit', 'nick']: 557 if event.eventtype() in ['quit', 'nick']:
519 for bridge in self.iter_bridges(irc_server=connection.server): 558 for bridge in self.iter_bridges(irc_server=connection.server):
520 559
521 try: 560 try:
539 from_.change_nickname(event.target(), 'xmpp') 578 from_.change_nickname(event.target(), 'xmpp')
540 continue 579 continue
541 580
542 if handled: 581 if handled:
543 return 582 return
544
545
546 # Connection errors
547 if event.eventtype() in ['disconnect', 'kill', 'error']:
548 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
549 self.error(2, debug_str, debug=True)
550 else:
551 self.error(say_levels.debug, debug_str, send_to_admins=True)
552 return
553
554
555 # Chan errors
556 if event.eventtype() in ['cannotsendtochan', 'notonchannel']:
557 self.error(2, debug_str, debug=True)
558
559 bridge = self.get_bridge(irc_room=event.arguments()[0], irc_server=connection.server)
560
561 if event.eventtype() == 'cannotsendtochan':
562 if connection.nickname == self.nickname:
563 bridge._join_irc_failed(event.eventtype())
564 else:
565 p = bridge.get_participant(connection.nickname)
566 p._close_irc_connection(event.eventtype())
567 p.irc_connection = event.eventtype()
568
569 elif event.eventtype() == 'notonchannel':
570 if connection.nickname == self.nickname:
571 bridge.restart(message='Restarting bridge because we received the IRC event '+event.eventtype())
572 else:
573 p = bridge.get_participant(connection.nickname)
574 p.irc_connection.join(bridge.irc_room)
575
576 return
577
578
579 # Ignore events not received on bot connection
580 if connection.nickname != self.nickname:
581 self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True)
582 return
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