forked from rDrama/rDrama
steal the parts I wanted from spidey's PR
parent
c70ea0eb64
commit
663904fb3d
|
@ -87,15 +87,10 @@ def NOTIFY_USERS(text, v):
|
||||||
if id == 0 or v.id == id: continue
|
if id == 0 or v.id == id: continue
|
||||||
if word in text.lower() and id not in notify_users: notify_users.add(id)
|
if word in text.lower() and id not in notify_users: notify_users.add(id)
|
||||||
|
|
||||||
captured = []
|
names = set(m.group(2) for m in mention_regex.finditer(text))
|
||||||
for i in mention_regex.finditer(text):
|
for user in get_users(names, graceful=True):
|
||||||
if v.username.lower() == i.group(2).lower(): continue
|
if v.id != user.id and not v.any_block_exists(user):
|
||||||
|
notify_users.add(user.id)
|
||||||
if i.group(0) in captured: continue
|
|
||||||
captured.append(i.group(0))
|
|
||||||
|
|
||||||
user = get_user(i.group(2), graceful=True)
|
|
||||||
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():
|
||||||
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level > 0).all()]
|
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level > 0).all()]
|
||||||
|
|
|
@ -244,21 +244,22 @@ def sanitize(sanitized, edit=False, limit_pings=0, showmore=True):
|
||||||
|
|
||||||
v = getattr(g, 'v', None)
|
v = getattr(g, 'v', None)
|
||||||
|
|
||||||
matches = [m for m in mention_regex.finditer(sanitized) if m]
|
names = set(m.group(2) for m in mention_regex.finditer(sanitized))
|
||||||
names = set(m.group(2) for m in matches)
|
if len(names) > 100 and not v.admin_level: abort(406)
|
||||||
if limit_pings and len(names) > limit_pings and not v.admin_level: abort(406)
|
users_list = get_users(names, graceful=True)
|
||||||
users = get_users(names, graceful=True)
|
users_dict = {}
|
||||||
|
for u in users_list:
|
||||||
|
users_dict[u.username.lower()] = u
|
||||||
|
if u.original_username:
|
||||||
|
users_dict[u.original_username.lower()] = u
|
||||||
|
|
||||||
for u in users:
|
def replacer(m):
|
||||||
if not u: continue
|
u = users_dict.get(m.group(2).lower())
|
||||||
m = [m for m in matches if u.username.lower() == m.group(2).lower() or u.original_username.lower() == m.group(2).lower()]
|
if not u:
|
||||||
for i in m:
|
return m.group(0)
|
||||||
if not (v and v.any_block_exists(u)) or (v and v.admin_level >= 2):
|
return f'{m.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>'
|
||||||
sanitized = re.sub(
|
|
||||||
f'{i.group(0)}($|[^a-zA-Z0-9_\-])',
|
sanitized = mention_regex.sub(replacer, sanitized)
|
||||||
rf'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>\1''',
|
|
||||||
sanitized
|
|
||||||
)
|
|
||||||
|
|
||||||
soup = BeautifulSoup(sanitized, 'lxml')
|
soup = BeautifulSoup(sanitized, 'lxml')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue