fix pinging

master
Aevann1 2022-08-19 15:10:39 +02:00
parent a39c4b6b72
commit d8c6b575de
3 changed files with 6 additions and 6 deletions

View File

@ -89,12 +89,12 @@ def NOTIFY_USERS(text, v):
captured = [] captured = []
for i in mention_regex.finditer(text): for i in mention_regex.finditer(text):
if v.username.lower() == i.group(2).lower(): continue if v.username.lower() == i.group(1).lower(): continue
if i.group(0) in captured: continue if i.group(0) in captured: continue
captured.append(i.group(0)) captured.append(i.group(0))
user = get_user(i.group(2), graceful=True) user = get_user(i.group(1), graceful=True)
if user and v.id != user.id and not v.any_block_exists(user): notify_users.add(user.id) if user and v.id != user.id and not v.any_block_exists(user): notify_users.add(user.id)
if SITE_NAME == "WPD" and 'daisy' in text.lower(): if SITE_NAME == "WPD" and 'daisy' in text.lower():

View File

@ -4,7 +4,7 @@ from random import choice, choices
valid_username_chars = 'a-zA-Z0-9_\-' valid_username_chars = 'a-zA-Z0-9_\-'
valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$", flags=re.A) valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$", flags=re.A)
mention_regex = re.compile('(?<=(\s|>))@(([a-zA-Z0-9_\-]){1,25})($|\s|<\/p>)', flags=re.A) mention_regex = re.compile('@(([a-zA-Z0-9_\-]){1,25})($|[^a-zA-Z0-9_\-])', flags=re.A)
valid_password_regex = re.compile("^.{8,100}$", flags=re.A) valid_password_regex = re.compile("^.{8,100}$", flags=re.A)

View File

@ -245,16 +245,16 @@ def sanitize(sanitized, edit=False, limit_pings=False, showmore=True):
v = getattr(g, 'v', None) v = getattr(g, 'v', None)
matches = [m for m in mention_regex.finditer(sanitized) if m] matches = [m for m in mention_regex.finditer(sanitized) if m]
names = set(m.group(2) for m in matches) names = set(m.group(1) for m in matches)
if limit_pings and len(names) > 3 and not v.admin_level: abort(406) if limit_pings and len(names) > 3 and not v.admin_level: abort(406)
users = get_users(names, graceful=True) users = get_users(names, graceful=True)
for u in users: for u in users:
if not u: continue if not u: continue
m = [m for m in matches if u.username.lower() == m.group(2).lower() or u.original_username.lower() == m.group(2).lower()] m = [m for m in matches if u.username.lower() == m.group(1).lower() or u.original_username.lower() == m.group(1).lower()]
for i in m: for i in m:
if not (v and v.any_block_exists(u)) or (v and v.admin_level >= 2): if not (v and v.any_block_exists(u)) or (v and v.admin_level >= 2):
sanitized = sanitized.replace(i.group(0), f'''<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>{i.group(4)}''') sanitized = sanitized.replace(i.group(0), f'''<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>{i.group(3)}''')
soup = BeautifulSoup(sanitized, 'lxml') soup = BeautifulSoup(sanitized, 'lxml')