From aa44bc15a37ef690eb1cc47d5f8d315116b919a0 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 15 Oct 2017 01:28:21 -0700 Subject: [PATCH] classes: fix backwards sorting in Channel.sort_prefixes() Also remove various workaround code added to address this. --- classes.py | 5 ++--- plugins/relay.py | 5 +---- protocols/p10.py | 7 +++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/classes.py b/classes.py index 2eed1c9..baf10e9 100644 --- a/classes.py +++ b/classes.py @@ -1722,10 +1722,9 @@ class Channel(structures.DeprecatedAttributesObject, structures.CamelCaseToSnake 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} + values = {'owner': 0, 'admin': 100, 'op': 200, 'halfop': 300, 'voice': 500} - # Default to highest value (1000) for unknown modes, should we choose to - # support them. + # Default to highest value (1000) for unknown modes, should they appear. return values.get(key, 1000) def get_prefix_modes(self, uid, prefixmodes=None): diff --git a/plugins/relay.py b/plugins/relay.py index 20d407c..0f48ef2 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -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: # 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 - # (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)): + for pmode in irc.channels[channel].get_prefix_modes(user, prefixmodes=mlist): if pmode in remoteirc.cmodes: modes += remoteirc.cmodes[pmode] return modes diff --git a/protocols/p10.py b/protocols/p10.py index b6dbfe6..c0d86f6 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -616,7 +616,7 @@ class P10Protocol(IRCS2SProtocol): # 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. - 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 # 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 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, '')[::-1] + + first_prefix = names_dict.get(first_uid, '') log.debug('(%s) sjoin: prefixes for first user %s: %s (post-wrap fixing)', self.name, first_uid, first_prefix)