fix two bugs in ping group charging logic for friends and enemies

master
Aevann 2024-02-03 03:45:54 +02:00
parent bbc7ba4de0
commit 929a228325
2 changed files with 27 additions and 17 deletions

View File

@ -137,7 +137,7 @@ def add_notif(cid, uid, text, pushnotif_url='', check_existing=True):
push_notif({uid}, 'New notification', text, pushnotif_url)
def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=True, commenters_ping_post_id=None):
def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=True, commenters_ping_post_id=None, charge=True):
# Restrict young accounts from generating notifications
if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD:
return set()
@ -178,6 +178,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
abort(403, f"Only admins can mention !focusgroup")
if i.group(1) == 'everyone':
if charge:
cost = g.db.query(User).count() * 5
if cost > v.coins + v.marseybux:
abort(403, f"You need {cost} currency to mention these ping groups!")
@ -224,6 +225,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
if i.group(1) in {'biofoids','neofoids','jannies'}:
coin_receivers.update(member_ids)
if charge:
if cost:
v.charge_account('coins/marseybux', cost)
if obj:

View File

@ -277,7 +277,11 @@ def settings_personal_post(v):
add_notif(cid, x, text, pushnotif_url=f'{SITE_FULL}{v.url}')
if v.friends:
removed_users = NOTIFY_USERS(v.friends, v) - NOTIFY_USERS(friends, v)
try:
removed_users = NOTIFY_USERS(v.friends, v, charge=False) - NOTIFY_USERS(friends, v, charge=False)
except TypeError:
pass
else:
notify_removed_users(removed_users, 'friends')
v.friends = friends
@ -307,7 +311,11 @@ def settings_personal_post(v):
add_notif(cid, x, text, pushnotif_url=f'{SITE_FULL}{v.url}')
if v.enemies:
removed_users = NOTIFY_USERS(v.enemies, v) - NOTIFY_USERS(enemies, v)
try:
removed_users = NOTIFY_USERS(v.enemies, v, charge=False) - NOTIFY_USERS(enemies, v, charge=False)
except TypeError:
pass
else:
notify_removed_users(removed_users, 'enemies')
v.enemies = enemies