Fix remove_notifications() for strings with multiple occurrences.

master
float-trip 2023-07-10 00:57:07 +00:00
parent f5c7ac30f7
commit 71b3ab2bf6
1 changed files with 6 additions and 3 deletions

View File

@ -44,10 +44,13 @@ def remove_notifications(text):
"soren", "soren",
] ]
def replace(match):
# Insert <i></i> after the first character of the matched string.
user = match.group()
return f"{user[:1]}<i></i>{user[1:]}"
for user in notified_users: for user in notified_users:
match = re.search(user, text, re.IGNORECASE) text = re.sub(user, replace, text, flags=re.IGNORECASE)
if match:
text = f"{text[:match.start() + 1]}<i></i>{text[match.start() + 1:]}"
return text return text