nova-api/rewards/autocredits.py

25 lines
580 B
Python
Raw Normal View History

2023-08-16 16:27:16 +02:00
import os
2023-08-07 14:55:53 +02:00
2023-08-16 16:27:16 +02:00
from dotenv import load_dotenv
load_dotenv()
async def get_all_users(client):
users = client[os.getenv('MONGO_NAME', 'nova-test')]['users']
return users
2023-08-07 14:55:53 +02:00
async def update_credits(pymongo_client, settings=None):
2023-08-16 16:27:16 +02:00
users = await get_all_users(pymongo_client)
2023-08-07 14:55:53 +02:00
2023-08-06 02:14:46 +02:00
if not settings:
users.update_many({}, {'$inc': {'credits': 2500}})
2023-08-06 02:14:46 +02:00
else:
for key, value in settings.items():
2023-08-07 14:55:53 +02:00
users.update_many(
2023-08-16 16:27:16 +02:00
{'level': key},
{'$inc':
{'credits': int(value)}
}
)