3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

classes: return valid channels as-is in get_friendly_name()

This makes it safe to use when processing message targets. (ref #153)
This commit is contained in:
James Lu 2018-05-11 14:40:24 -07:00
parent 0ac5d424d8
commit 244c4fe0eb

View File

@ -1172,12 +1172,16 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
def get_friendly_name(self, entityid): def get_friendly_name(self, entityid):
""" """
Returns the friendly name of a SID or UID (server name for SIDs, nick for UID). Returns the friendly name of a SID (the server name), UID (the nick), or channel (returned as-is).
""" """
if entityid in self.servers: if entityid in self.servers:
return self.servers[entityid].name return self.servers[entityid].name
elif entityid in self.users: elif entityid in self.users:
return self.users[entityid].nick return self.users[entityid].nick
elif self.is_channel(entityid):
# We assume that channels don't conflict with the SID/UID format. For IRC, this is a
# relatively safe bet.
return entityid
else: else:
raise KeyError("Unknown UID/SID %s" % entityid) raise KeyError("Unknown UID/SID %s" % entityid)