From b6d4ecfb40de65fb4fe3de17b830310e99f0f772 Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 25 Apr 2023 08:59:20 +0200 Subject: [PATCH] fix repeated group pings --- files/helpers/sanitize.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 54340521f..fdb3e98b9 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -377,14 +377,18 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_emojis= sanitized = mention_regex.sub(replacer, sanitized) if FEATURES['PING_GROUPS']: - for i in group_mention_regex.finditer(sanitized): - name = i.group(1).lower() + def group_replacer(m): + name = m.group(1).lower() + if name == 'everyone': - sanitized = group_mention_regex.sub(r'!\1', sanitized) + return f'!{name}' + elif g.db.get(Group, name): + return f'!{name}' else: - existing = g.db.get(Group, name) - if existing: - sanitized = sanitized.replace(i.group(0), f'!{name}', 1) + return m.group(0) + + sanitized = group_mention_regex.sub(group_replacer, sanitized) + soup = BeautifulSoup(sanitized, 'lxml')