From e21ecaa6196f145434b5b1b64192363dc4b2cbc5 Mon Sep 17 00:00:00 2001 From: nsde Date: Wed, 20 Sep 2023 00:46:20 +0200 Subject: [PATCH] began with the reset_key command. It's still a bit fucked --- cord/__main__.py | 0 cord/accounts.py | 46 +++++++++++++++++++++++++++++++++----- cord/api.py | 0 cord/autochat.py | 0 cord/bot.py | 0 cord/chatbot.py | 0 cord/community.py | 0 cord/credential_manager.py | 0 cord/embedder.py | 0 cord/tos_verification.py | 0 cord/tutorials.py | 0 11 files changed, 40 insertions(+), 6 deletions(-) mode change 100644 => 100755 cord/__main__.py mode change 100644 => 100755 cord/accounts.py mode change 100644 => 100755 cord/api.py mode change 100644 => 100755 cord/autochat.py mode change 100644 => 100755 cord/bot.py mode change 100644 => 100755 cord/chatbot.py mode change 100644 => 100755 cord/community.py mode change 100644 => 100755 cord/credential_manager.py mode change 100644 => 100755 cord/embedder.py mode change 100644 => 100755 cord/tos_verification.py mode change 100644 => 100755 cord/tutorials.py diff --git a/cord/__main__.py b/cord/__main__.py old mode 100644 new mode 100755 diff --git a/cord/accounts.py b/cord/accounts.py old mode 100644 new mode 100755 index 3eea3db..df716a8 --- a/cord/accounts.py +++ b/cord/accounts.py @@ -3,6 +3,8 @@ import os import json import requests +import string +import random import embedder @@ -124,11 +126,43 @@ Please report this issue to the staff!""", ephemeral=True) await embedder.ok(interaction, f"""Successfully set the credits of {user.name} to **{amount}**.""", ephemeral=True) async def reset_key(interaction): - account = await get_account(interaction) - if not account: - interaction.message.reply("""You don't have an account yet!""") - - print(account) + return await embedder.error(interaction, """Not finished yet""", ephemeral=True) - interaction.message.reply("""1""") \ No newline at end of file + try: + account = await get_account(interaction) + + if not account: + await embedder.error(interaction, """It seems like you don't have an account yet.""", ephemeral=True) + + requests.put( + url=f'http://localhost:2333/users', + timeout=3, + headers={ + 'Content-Type': 'application/json', + 'Authorization': os.getenv('CORE_API_KEY') + }, + data=json.dumps({ + "discord_id": account["auth"]["discord"], + "updates": {"$set": {"api_key": await new_api_key()}} + }) + ) + + await embedder.ok(interaction, f"""Successfully reset your key!""", ephemeral=True) + + except Exception as exc: + await embedder.error(interaction, """Sorry, there was an error while resetting your key. +Please report this issue to the staff!""", ephemeral=True) + raise exc + + +async def new_api_key() -> str: + chars = string.ascii_letters + string.digits + + infix = os.getenv('KEYGEN_INFIX') + suffix = ''.join(random.choices(chars, k=20)) + prefix = ''.join(random.choices(chars, k=20)) + + new_api_key = f'nv-{prefix}{infix}{suffix}' + + return new_api_key \ No newline at end of file diff --git a/cord/api.py b/cord/api.py old mode 100644 new mode 100755 diff --git a/cord/autochat.py b/cord/autochat.py old mode 100644 new mode 100755 diff --git a/cord/bot.py b/cord/bot.py old mode 100644 new mode 100755 diff --git a/cord/chatbot.py b/cord/chatbot.py old mode 100644 new mode 100755 diff --git a/cord/community.py b/cord/community.py old mode 100644 new mode 100755 diff --git a/cord/credential_manager.py b/cord/credential_manager.py old mode 100644 new mode 100755 diff --git a/cord/embedder.py b/cord/embedder.py old mode 100644 new mode 100755 diff --git a/cord/tos_verification.py b/cord/tos_verification.py old mode 100644 new mode 100755 diff --git a/cord/tutorials.py b/cord/tutorials.py old mode 100644 new mode 100755