forked from rDrama/rDrama
1
0
Fork 0

make alerts more forgiving

master
Aevann 2023-03-11 07:07:10 +02:00
parent 02c9f446a5
commit fb57d433cd
2 changed files with 9 additions and 5 deletions

View File

@ -134,7 +134,8 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False):
if word in text: if word in text:
notify_users.add(id) notify_users.add(id)
names = set(m.group(2) for m in mention_regex.finditer(text)) names = set(m.group(1) for m in mention_alerts_regex.finditer(text))
user_ids = get_users(names, ids_only=True, graceful=True) user_ids = get_users(names, ids_only=True, graceful=True)
notify_users.update(user_ids) notify_users.update(user_ids)
@ -148,11 +149,11 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False):
if FEATURES['PING_GROUPS']: if FEATURES['PING_GROUPS']:
cost = 0 cost = 0
for i in group_mention_regex.finditer(text): for i in group_mention_alerts_regex.finditer(text):
if oldtext and i.group(2) in oldtext: if oldtext and i.group(1) in oldtext:
continue continue
if i.group(2) == 'everyone' and not v.shadowbanned: if i.group(1) == 'everyone' and not v.shadowbanned:
cost = g.db.query(User).count() * 5 cost = g.db.query(User).count() * 5
if cost > v.coins: if cost > v.coins:
abort(403, f"You need {cost} coins for this!") abort(403, f"You need {cost} coins for this!")
@ -160,7 +161,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False):
v.charge_account('coins', cost) v.charge_account('coins', cost)
return 'everyone' return 'everyone'
else: else:
group = g.db.get(Group, i.group(2)) group = g.db.get(Group, i.group(1))
if not group: continue if not group: continue
members = group.member_ids - notify_users - v.all_twoway_blocks members = group.member_ids - notify_users - v.all_twoway_blocks

View File

@ -7,9 +7,12 @@ from .config.const import *
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,30})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A) mention_regex = re.compile('(^|\s|>)@([a-zA-Z0-9_\-]{1,30})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)
mention_alerts_regex = re.compile('@([a-zA-Z0-9_\-]{1,30})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)
group_mention_regex = re.compile('(^|\s|>)!([a-z0-9_\-]{3,25})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A|re.I) group_mention_regex = re.compile('(^|\s|>)!([a-z0-9_\-]{3,25})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A|re.I)
group_mention_alerts_regex = re.compile('!([a-z0-9_\-]{3,25})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A|re.I)
everyone_regex = re.compile('(^|\s|>)!(everyone)(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A) everyone_regex = re.compile('(^|\s|>)!(everyone)(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)