comparison bot.py @ 53:a2258a705a17

Handle kick (by simply rejoining) on IRC side Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 26 Aug 2009 18:47:46 +0200
parents 5aabf124c78d
children 2507f424773a
comparison
equal deleted inserted replaced
52:5aabf124c78d 53:a2258a705a17
268 268
269 # A string representation of the event 269 # A string representation of the event
270 event_str = '==> Debug: Received IRC event.\nconnection='+str(connection)+'\neventtype='+event.eventtype()+'\nsource='+str(event.source())+'\ntarget='+str(event.target())+'\narguments='+str(event.arguments()) 270 event_str = '==> Debug: Received IRC event.\nconnection='+str(connection)+'\neventtype='+event.eventtype()+'\nsource='+str(event.source())+'\ntarget='+str(event.target())+'\narguments='+str(event.arguments())
271 271
272 272
273 if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick']: 273 if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']:
274 if nickname == None: 274 if nickname == None:
275 return 275 return
276 276
277 handled = False 277 handled = False
278 278
279 if event.eventtype() in ['quit', 'part', 'nick']: 279 if event.eventtype() in ['quit', 'part', 'nick', 'kick']:
280 self.error(event_str, debug=True) 280 if connection.get_nickname() != self.nickname:
281 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
282 return
283 else:
284 self.error(event_str, debug=True)
285
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')
288 return
281 289
282 if event.eventtype() in ['pubmsg', 'action'] and nickname == self.nickname: 290 if event.eventtype() in ['pubmsg', 'action'] and nickname == self.nickname:
283 self.error('=> Debug: ignoring IRC '+event.eventtype()+' sent by self', debug=True) 291 self.error('=> Debug: ignoring IRC '+event.eventtype()+' sent by self', debug=True)
284 return 292 return
285 293
314 return 322 return
315 else: 323 else:
316 continue 324 continue
317 325
318 326
319 # From here we skip if the event was not received on bot connection 327 # Rejoin on kick
320 if connection.get_nickname() != self.nickname: 328 if event.eventtype() == 'kick':
321 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) 329 if event.target().lower() == bridge.irc_room:
322 continue 330 try:
331 kicked = bridge.getParticipant(event.arguments()[0])
332 if kicked.irc_connection != None:
333 kicked.irc_connection.join(bridge.irc_room)
334 except NoSuchParticipantException:
335 self.error('=> Debug: a participant that was not here has been kicked ? WTF ?')
336 return
337 else:
338 continue
339
323 340
324 # Leaving events 341 # Leaving events
325 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room: 342 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room:
326 if len(event.arguments()) > 0: 343 if len(event.arguments()) > 0:
327 leave_message = event.arguments()[0] 344 leave_message = event.arguments()[0]
354 return 371 return
355 else: 372 else:
356 continue 373 continue
357 374
358 if handled == False: 375 if handled == False:
359 if not event.eventtype() in ['quit', 'part', 'nick']: 376 if not event.eventtype() in ['quit', 'part', 'nick', 'kick']:
360 self.error(event_str, debug=True) 377 self.error(event_str, debug=True)
361 self.error('=> Debug: event was not handled', debug=True) 378 self.error('=> Debug: event was not handled', debug=True)
362 return 379 return
363 380
364 381