3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-03 08:04:07 +01:00

service_support: reuse existing internal clients for service bots if one exists

Potential fix for #458.
This commit is contained in:
James Lu 2017-05-12 18:27:54 -07:00
parent daa6593534
commit 457325024a

View File

@ -48,7 +48,13 @@ def spawn_service(irc, source, command, args):
modes.append((mode, None)) modes.append((mode, None))
# Track the service's UIDs on each network. # Track the service's UIDs on each network.
log.debug('(%s) Using nick %s for service %s', irc.name, nick, name) log.debug('(%s) spawn_service: Using nick %s for service %s', irc.name, nick, name)
u = irc.nickToUid(nick)
if u and irc.isInternalClient(u): # If an internal client exists, reuse it.
log.debug('(%s) spawn_service: Using existing client %s/%s', irc.name, u, nick)
userobj = irc.users[u]
else:
log.debug('(%s) spawn_service: Spawning new client %s', irc.name, nick)
userobj = irc.proto.spawnClient(nick, ident, host, modes=modes, opertype="PyLink Service", userobj = irc.proto.spawnClient(nick, ident, host, modes=modes, opertype="PyLink Service",
manipulatable=sbot.manipulatable) manipulatable=sbot.manipulatable)
@ -60,7 +66,7 @@ def spawn_service(irc, source, command, args):
# Special case: if this is the main PyLink client being spawned, # Special case: if this is the main PyLink client being spawned,
# assign this as irc.pseudoclient. # assign this as irc.pseudoclient.
if name == 'pylink': if name == 'pylink':
log.debug('(%s) irc.pseudoclient set to UID %s', irc.name, u) log.debug('(%s) spawn_service: irc.pseudoclient set to UID %s', irc.name, u)
irc.pseudoclient = userobj irc.pseudoclient = userobj
channels = set(irc.serverdata.get(name+'_channels', [])) | set(irc.serverdata.get('channels', [])) | \ channels = set(irc.serverdata.get(name+'_channels', [])) | set(irc.serverdata.get('channels', [])) | \