Compare commits

..

No commits in common. "e4313b439a47c8ae399d2e6fba51c07e9dfb54b4" and "c07af0aed8767d19b14b8082a6d9826d9a42ca3f" have entirely different histories.

4 changed files with 19 additions and 47 deletions

View file

@ -1,12 +0,0 @@
import os
def find_project_root():
current_path = os.getcwd()
while not os.path.isfile(os.path.join(current_path, 'LICENSE')):
current_path = os.path.dirname(current_path)
return current_path
root = find_project_root()
if __name__ == '__main__':
print(find_project_root())

View file

@ -7,14 +7,9 @@ import asyncio
from dotenv import load_dotenv
from motor.motor_asyncio import AsyncIOMotorClient
try:
from . import helpers
except ImportError:
import helpers
load_dotenv()
with open(helpers.root + '/api/config/config.yml', encoding='utf8') as f:
with open('config/config.yml', encoding='utf8') as f:
credits_config = yaml.safe_load(f)
## MONGODB Setup
@ -41,8 +36,7 @@ class UserManager:
return self.conn[os.getenv('MONGO_NAME', 'nova-test')][collection_name]
async def get_all_users(self):
collection = self.conn[os.getenv('MONGO_NAME', 'nova-test')]['users']
return collection#.find()
return self.conn[os.getenv('MONGO_NAME', 'nova-test')]['users']
async def create(self, discord_id: str = '') -> dict:
chars = string.ascii_letters + string.digits

View file

@ -1,22 +1,17 @@
import os
import sys
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(project_root)
# Weird hack because PYTHON IS GOOD LANGUAGE :))))
sys.path.append('../')
from api.db.users import UserManager
manager = UserManager()
async def update_credits(settings=None):
users = await manager.get_all_users()
async def update_credits(pymongo_client, settings=None):
manager = UserManager()
users = await manager.get_all_users(pymongo_client)
if not settings:
await users.update_many({}, {'$inc': {'credits': 2500}})
users.update_many({}, {'$inc': {'credits': 2500}})
else:
for key, value in settings.items():
await users.update_many(
users.update_many(
{'level': key}, {'$inc': {'credits': int(value)}})
get_all_users = manager.get_all_users

View file

@ -9,12 +9,13 @@ from settings import roles
from dotenv import load_dotenv
load_dotenv()
async def main():
await update_roles()
await autocredits.update_credits(roles)
mongo = pymongo.MongoClient(os.getenv('MONGO_URI'))
async def update_roles():
await update_roles(mongo)
await autocredits.update_credits(mongo, roles)
async def update_roles(mongo):
async with aiohttp.ClientSession() as session:
try:
async with session.get('http://0.0.0.0:3224/get_roles') as response:
@ -24,26 +25,19 @@ async def update_roles():
return
level_role_names = [f'lvl{lvl}' for lvl in range(10, 110, 10)]
users_doc = await autocredits.get_all_users()
users = users_doc.find({})
users = await users.to_list(length=None)
for user in users:
if not 'auth' in user:
continue
users = await autocredits.get_all_users(mongo)
for user in users.find():
discord = str(user['auth']['discord'])
for user_id, role_names in discord_users.items():
if user_id == discord:
for role in level_role_names:
if role in role_names:
users_doc.update_one(
users.update_one(
{'auth.discord': discord},
{'$set': {'level': role}}
)
print(f'Updated {discord} to {role}')
return users
@ -51,8 +45,9 @@ async def update_roles():
def launch():
asyncio.run(main())
with open('rewards/last_update.txt', 'w', encoding='utf8') as f:
with open('rewards/last_update.txt', 'w') as f:
f.write(str(time.time()))
if __name__ == '__main__':
launch()