From 5590cfc90f150ca61d4b0ae6a77183f47cc660aa Mon Sep 17 00:00:00 2001 From: Ske Date: Fri, 26 Apr 2019 18:21:16 +0200 Subject: [PATCH] bot: fix handling of tag supersets (see #84 comments) --- src/pluralkit/system.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pluralkit/system.py b/src/pluralkit/system.py index 02c78161..dd8cb09d 100644 --- a/src/pluralkit/system.py +++ b/src/pluralkit/system.py @@ -192,9 +192,8 @@ class System(namedtuple("System", ["id", "hid", "name", "description", "tag", "a """Tries to find a member with proxy tags matching the given message. Returns the member and the inner contents.""" members = await db.get_all_members(conn, self.id) - # Sort by specificity (members with both prefix and suffix defined go higher) - # This will make sure more "precise" proxy tags get tried first and match properly - members = sorted(members, key=lambda x: int(bool(x.prefix)) + int(bool(x.suffix)), reverse=True) + # Sort by match specificity (longer prefix/suffix = smaller match = more specific) + members = sorted(members, key=lambda x: len(x.prefix or "") + len(x.suffix or ""), reverse=True) for member in members: proxy_prefix = member.prefix or ""