Fixed the autocredits

This commit is contained in:
nsde 2023-08-16 16:27:16 +02:00
parent f6cd1f7aa2
commit f9edbf1bc0

View file

@ -1,9 +1,15 @@
from users import UserManager import os
from dotenv import load_dotenv
load_dotenv()
async def get_all_users(client):
users = client[os.getenv('MONGO_NAME', 'nova-test')]['users']
return users
async def update_credits(pymongo_client, settings=None): async def update_credits(pymongo_client, settings=None):
manager = UserManager() users = await get_all_users(pymongo_client)
users = await manager.get_all_users(pymongo_client)
if not settings: if not settings:
users.update_many({}, {'$inc': {'credits': 2500}}) users.update_many({}, {'$inc': {'credits': 2500}})
@ -11,4 +17,8 @@ async def update_credits(pymongo_client, settings=None):
else: else:
for key, value in settings.items(): for key, value in settings.items():
users.update_many( users.update_many(
{'level': key}, {'$inc': {'credits': int(value)}}) {'level': key},
{'$inc':
{'credits': int(value)}
}
)