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

Irc: consistently sort getPrefixModes output

This commit is contained in:
James Lu 2016-07-11 15:21:17 -07:00
parent 2c656341e2
commit 2a08ae98b0

View File

@ -1092,6 +1092,18 @@ class IrcChannel():
return True
return False
@staticmethod
def sortPrefixes(key):
"""
Implements a sorted()-compatible sorter for prefix modes, giving each one a
numeric value.
"""
values = {'owner': 100, 'admin': 10, 'op': 5, 'halfop': 4, 'voice': 3}
# Default to highest value (1000) for unknown modes, should we choose to
# support them.
return values.get(key, 1000)
def getPrefixModes(self, uid, prefixmodes=None):
"""Returns a list of all named prefix modes the given user has in the channel.
@ -1110,7 +1122,7 @@ class IrcChannel():
if uid in modelist:
result.append(mode)
return result
return sorted(result, key=self.sortPrefixes)
class Protocol():
"""Base Protocol module class for PyLink."""