3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 03:33:10 +01:00

service_support: consistently rejoin all channels on kick and kill

This is the cheap fix to part one of #265: "When a services client is killed, it won't join any relay leaf channels"
This commit is contained in:
James Lu 2018-04-13 20:34:26 -07:00
parent 4cdc19ac78
commit 3c9dac7e6b

View File

@ -107,17 +107,26 @@ def handle_kill(irc, source, command, args):
irc.pseudoclient = None
userdata = args.get('userdata')
sbot = irc.get_service_bot(target)
servicename = None
if userdata and hasattr(userdata, 'service'): # Look for the target's service name attribute
servicename = userdata.service
elif sbot: # Or their service bot instance
servicename = None
channels = []
if userdata:
# Look for the target's service name
servicename = getattr(userdata, 'service', servicename)
channels = getattr(userdata, 'channels', channels)
elif sbot:
# Or its service bot instance
servicename = sbot.name
channels = irc.users[target].channels
if servicename:
log.info('(%s) Received kill to service %r (nick: %r) from %s (reason: %r).', irc.name, servicename,
userdata.nick if userdata else irc.users[target].nick, irc.get_hostmask(source), args.get('text'))
spawn_service(irc, source, command, {'name': servicename})
# Rejoin the killed service bot to all channels it was previously in.
world.services[servicename].join(irc, channels)
utils.add_hook(handle_kill, 'KILL')
def handle_join(irc, source, command, args):
@ -156,7 +165,7 @@ def handle_kick(irc, source, command, args):
if not _services_dynamic_part(irc, channel):
kicked = args['target']
sbot = irc.get_service_bot(kicked)
if sbot and channel in sbot.get_persistent_channels(irc):
if sbot:
sbot.join(irc, channel)
utils.add_hook(handle_kick, 'KICK')