nova-api/rewards/autocredits.py

25 lines
607 B
Python
Raw Permalink Normal View History

2023-08-19 13:30:46 +02:00
import os
import sys
2023-08-19 13:30:46 +02:00
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(project_root)
from api.db.users import UserManager
2023-08-07 14:55:53 +02:00
2023-08-19 13:30:46 +02:00
manager = UserManager()
2023-08-07 14:55:53 +02:00
2023-08-19 13:30:46 +02:00
async def update_credits(settings=None):
2023-10-12 00:03:15 +02:00
"""Updates the credits of all users."""
2023-08-19 13:30:46 +02:00
users = await manager.get_all_users()
2023-08-07 14:55:53 +02:00
2023-08-06 02:14:46 +02:00
if not settings:
2023-08-19 13:30:46 +02:00
await users.update_many({}, {'$inc': {'credits': 2500}})
2023-08-06 02:14:46 +02:00
else:
for key, value in settings.items():
2023-08-19 13:30:46 +02:00
await users.update_many(
{'level': key}, {'$inc': {'credits': int(value)}})
2023-08-19 13:30:46 +02:00
get_all_users = manager.get_all_users