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

Irc: add getFriendlyName() abstraction

Closes #260.
This commit is contained in:
James Lu 2016-07-06 22:28:55 -07:00
parent 3f1ad01ac6
commit e0f050c195
2 changed files with 14 additions and 7 deletions

View File

@ -871,6 +871,16 @@ class Irc():
return '%s!%s@%s' % (nick, ident, host)
def getFriendlyName(self, entityid):
"""
Returns the friendly name of a SID or UID (server name for SIDs, nick for UID)."""
if entityid in self.servers:
return self.servers[entityid].name
elif entityid in self.users:
return self.users[entityid].nick
else:
raise KeyError("Unknown UID/SID %s" % entityid)
def isOper(self, uid, allowAuthed=True, allowOper=True):
"""
Returns whether the given user has operator status on PyLink. This can be achieved

View File

@ -24,13 +24,10 @@ class IRCS2SProtocol(Protocol):
# What we actually want is to format a pretty kill message, in the form
# "Killed (killername (reason))".
if source in self.irc.users:
# Killer was a user (they're SO fired)
killer = self.irc.users[source].nick
elif source in self.irc.servers:
# Killer was a server (impossible, the machine is always right)
killer = self.irc.servers[source].name
else:
try:
# Get the nick or server name of the caller.
killer = self.irc.getFriendlyName(source)
except KeyError:
# Killer was... neither? We must have aliens or something. Fallback
# to the given "UID".
killer = source