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

classes: fix backwards sorting in Channel.sort_prefixes()

Also remove various workaround code added to address this.
This commit is contained in:
James Lu 2017-10-15 01:28:21 -07:00
parent b8df1a1b61
commit aa44bc15a3
3 changed files with 6 additions and 11 deletions

View File

@ -1722,10 +1722,9 @@ class Channel(structures.DeprecatedAttributesObject, structures.CamelCaseToSnake
Implements a sorted()-compatible sorter for prefix modes, giving each one a Implements a sorted()-compatible sorter for prefix modes, giving each one a
numeric value. numeric value.
""" """
values = {'owner': 100, 'admin': 10, 'op': 5, 'halfop': 4, 'voice': 3} values = {'owner': 0, 'admin': 100, 'op': 200, 'halfop': 300, 'voice': 500}
# Default to highest value (1000) for unknown modes, should we choose to # Default to highest value (1000) for unknown modes, should they appear.
# support them.
return values.get(key, 1000) return values.get(key, 1000)
def get_prefix_modes(self, uid, prefixmodes=None): def get_prefix_modes(self, uid, prefixmodes=None):

View File

@ -209,10 +209,7 @@ def get_prefix_modes(irc, remoteirc, channel, user, mlist=None):
if channel in irc.channels and user in irc.channels[channel].users: if channel in irc.channels and user in irc.channels[channel].users:
# Iterate over the the prefix modes for relay supported by the remote IRCd. # Iterate over the the prefix modes for relay supported by the remote IRCd.
# Note: reverse the order so prefix modes are bursted in their traditional order for pmode in irc.channels[channel].get_prefix_modes(user, prefixmodes=mlist):
# (e.g. owner before op before halfop). TODO: SJOIN modes should probably be
# consistently sorted IRCd-side.
for pmode in reversed(irc.channels[channel].get_prefix_modes(user, prefixmodes=mlist)):
if pmode in remoteirc.cmodes: if pmode in remoteirc.cmodes:
modes += remoteirc.cmodes[pmode] modes += remoteirc.cmodes[pmode]
return modes return modes

View File

@ -616,7 +616,7 @@ class P10Protocol(IRCS2SProtocol):
# Flip the (prefixmodes, user) pairs in users, and save it as a dict for easy lookup # Flip the (prefixmodes, user) pairs in users, and save it as a dict for easy lookup
# later of what modes each target user should have. # later of what modes each target user should have.
names_dict = dict([(uid, prefixes) for prefixes, uid in users]) names_dict = {uid: prefixes for prefixes, uid in users}
# Wrap all users and send them to prevent cutoff. Subtract 4 off the maximum # Wrap all users and send them to prevent cutoff. Subtract 4 off the maximum
# buf size to account for user prefix data that may be re-added (e.g. ":ohv") # buf size to account for user prefix data that may be re-added (e.g. ":ohv")
@ -633,9 +633,8 @@ class P10Protocol(IRCS2SProtocol):
# If the first UID was supposed to have a prefix mode attached, re-add it here # If the first UID was supposed to have a prefix mode attached, re-add it here
first_uid = wrapped_namelist[0] first_uid = wrapped_namelist[0]
# XXX: I'm not sure why the prefix list has to be reversed for it to match the
# original string... first_prefix = names_dict.get(first_uid, '')
first_prefix = names_dict.get(first_uid, '')[::-1]
log.debug('(%s) sjoin: prefixes for first user %s: %s (post-wrap fixing)', self.name, log.debug('(%s) sjoin: prefixes for first user %s: %s (post-wrap fixing)', self.name,
first_uid, first_prefix) first_uid, first_prefix)