comparison bot.py @ 58:92341dbfb8b7

Handle bannedfromchan IRC event Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 27 Aug 2009 22:35:18 +0200
parents b048c4c03b00
children 71508f22edb4
comparison
equal deleted inserted replaced
57:ebd4278e472f 58:92341dbfb8b7
282 return 282 return
283 else: 283 else:
284 self.error(event_str, debug=True) 284 self.error(event_str, debug=True)
285 285
286 if event.eventtype() == 'kick' and len(event.arguments()) < 1: 286 if event.eventtype() == 'kick' and len(event.arguments()) < 1:
287 self.error('=> Debug: length of arguments should be greater than 0 for a kick event') 287 self.error('=> Debug: length of arguments should be greater than 0 for a '+event.eventtype()+' event')
288 return 288 return
289 289
290 if event.eventtype() in ['pubmsg', 'action']: 290 if event.eventtype() in ['pubmsg', 'action']:
291 if connection.get_nickname() != self.nickname: 291 if connection.get_nickname() != self.nickname:
292 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True) 292 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
333 if event.target().lower() == bridge.irc_room: 333 if event.target().lower() == bridge.irc_room:
334 try: 334 try:
335 kicked = bridge.getParticipant(event.arguments()[0]) 335 kicked = bridge.getParticipant(event.arguments()[0])
336 if kicked.irc_connection != None: 336 if kicked.irc_connection != None:
337 kicked.irc_connection.join(bridge.irc_room) 337 kicked.irc_connection.join(bridge.irc_room)
338 return
338 except NoSuchParticipantException: 339 except NoSuchParticipantException:
339 self.error('=> Debug: a participant that was not here has been kicked ? WTF ?') 340 self.error('=> Debug: a participant that was not here has been kicked ? WTF ?')
340 return 341 return
341 else: 342 else:
342 continue 343 continue
381 self.error(event_str, debug=True) 382 self.error(event_str, debug=True)
382 self.error('=> Debug: event was not handled', debug=True) 383 self.error('=> Debug: event was not handled', debug=True)
383 return 384 return
384 385
385 386
387 # Handle bannedfromchan
388 if event.eventtype() == 'bannedfromchan':
389 if len(event.arguments()) < 1:
390 self.error('=> Debug: length of arguments should be greater than 0 for a '+event.eventtype()+' event')
391 return
392
393 for bridge in self.bridges:
394 if connection.server != bridge.irc_server or event.arguments()[0].lower() != bridge.irc_room:
395 continue
396
397 if event.target() == self.nickname:
398 self.error('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
399 raise Exception('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
400 else:
401 try:
402 banned = bridge.getParticipant(event.target())
403 if banned.irc_connection != None:
404 banned.irc_connection = None
405 self.error(event_str, debug=True)
406 self.error('[Notice] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
407 bridge.say('[Warning] the nickname "'+event.target()+'" is banned from the IRC chan')
408 else:
409 self.error('=> Debug: ignoring '+event.eventtype(), debug=True)
410 except NoSuchParticipantException:
411 self.error('=> Debug: no such participant. WTF ?')
412 return
413
414 return
415
416
417 # Joining events
386 if event.eventtype() in ['namreply', 'join']: 418 if event.eventtype() in ['namreply', 'join']:
387 if connection.get_nickname() != self.nickname: 419 if connection.get_nickname() != self.nickname:
388 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) 420 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True)
389 return 421 return
390 422
397 bridge.addParticipant('irc', nickname) 429 bridge.addParticipant('irc', nickname)
398 return 430 return
399 elif event.eventtype() == 'join': 431 elif event.eventtype() == 'join':
400 bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) 432 bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server)
401 if len(bridges) == 0: 433 if len(bridges) == 0:
434 self.error(event_str, debug=True)
402 self.error('===> Debug: no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) 435 self.error('===> Debug: no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True)
403 return 436 return
404 for bridge in bridges: 437 for bridge in bridges:
405 bridge.addParticipant('irc', nickname) 438 bridge.addParticipant('irc', nickname)
406 return 439 return
407 440
408 441
409 # From here the event is shown 442 # From here the event is shown
410 self.error(event_str, debug=True) 443 self.error(event_str, debug=True)
444
411 445
412 if event.eventtype() == 'disconnect': 446 if event.eventtype() == 'disconnect':
413 # TODO: lock self.bridges for thread safety 447 # TODO: lock self.bridges for thread safety
414 for bridge in self.bridges: 448 for bridge in self.bridges:
415 try: 449 try:
417 if bridge.mode == 'normal': 451 if bridge.mode == 'normal':
418 bridge.switchFromNormalToLimitedMode() 452 bridge.switchFromNormalToLimitedMode()
419 except NoSuchParticipantException: 453 except NoSuchParticipantException:
420 pass 454 pass
421 return 455 return
422 elif event.eventtype() == 'nicknameinuse': 456
457
458 # Nickname callbacks
459 # TODO: move this into irclib.py
460 if event.eventtype() == 'nicknameinuse':
423 connection._call_nick_callbacks('nicknameinuse') 461 connection._call_nick_callbacks('nicknameinuse')
424 return 462 return
425 elif event.eventtype() == 'erroneusnickname': 463 if event.eventtype() == 'erroneusnickname':
426 connection._call_nick_callbacks('erroneusnickname') 464 connection._call_nick_callbacks('erroneusnickname')
427 return 465 return
428 466
429 467
430 # Unhandled events 468 # Unhandled events