3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +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) 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): def isOper(self, uid, allowAuthed=True, allowOper=True):
""" """
Returns whether the given user has operator status on PyLink. This can be achieved 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 # What we actually want is to format a pretty kill message, in the form
# "Killed (killername (reason))". # "Killed (killername (reason))".
if source in self.irc.users: try:
# Killer was a user (they're SO fired) # Get the nick or server name of the caller.
killer = self.irc.users[source].nick killer = self.irc.getFriendlyName(source)
elif source in self.irc.servers: except KeyError:
# Killer was a server (impossible, the machine is always right)
killer = self.irc.servers[source].name
else:
# Killer was... neither? We must have aliens or something. Fallback # Killer was... neither? We must have aliens or something. Fallback
# to the given "UID". # to the given "UID".
killer = source killer = source