3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Irc, services_support: store service name in IrcUser objects (#355)

This commit is contained in:
James Lu 2016-11-09 19:07:01 -08:00
parent 0815df1bca
commit 08fa64c3cc
2 changed files with 16 additions and 5 deletions

View File

@ -907,11 +907,19 @@ class Irc():
Checks whether the given UID is a registered service bot. If True, Checks whether the given UID is a registered service bot. If True,
returns the cooresponding ServiceBot object. returns the cooresponding ServiceBot object.
""" """
if not uid: userobj = self.users.get(uid)
if not userobj:
return False return False
for sbot in world.services.values():
if uid == sbot.uids.get(self.name): # Look for the "service" attribute in the IrcUser object, if one exists.
return sbot try:
sname = userobj.service
# Warn if the service name we fetched isn't a registered service.
if sname not in world.services.keys():
log.warning("(%s) User %s / %s had a service bot record to a service that doesn't "
"exist (%s)!", self.name, uid, userobj.nick, sname)
return world.services.get(sname)
except AttributeError:
return False return False
def getHostmask(self, user, realhost=False, ip=False): def getHostmask(self, user, realhost=False, ip=False):

View File

@ -51,6 +51,9 @@ def spawn_service(irc, source, command, args):
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)
# Store the service name in the IrcUser object for easier access.
userobj.service = name
sbot.uids[irc.name] = u = userobj.uid sbot.uids[irc.name] = u = userobj.uid
# Special case: if this is the main PyLink client being spawned, # Special case: if this is the main PyLink client being spawned,