diff --git a/cord/accounts.py b/cord/accounts.py index 8b4f543..98d67df 100644 --- a/cord/accounts.py +++ b/cord/accounts.py @@ -81,3 +81,41 @@ Please report this issue to the staff!""", ephemeral=True) await embedder.info(interaction, f"""### Credits of {user.name} Amount: **{amount_credits if amount_credits < 1000000 else '∞'}** """, ephemeral=True) + +async def set_credits(interaction, user, amount): + if not interaction.user.guild_permissions.administrator: + await embedder.error(interaction, """Sorry, you don't have the permission to do that.""", ephemeral=True) + return + + try: + userinfo = await request_user_by_discord_id(user.id) + + except Exception as exc: + await embedder.error(interaction, """Sorry, there was an error while checking if you have an account. +Please report this issue to the staff!""", ephemeral=True) + raise exc + + if userinfo.status_code == 404: + await embedder.error(interaction, """You don't have an account yet!""", ephemeral=True) + return + + account = userinfo.json() + account["credits"] = amount + + try: + requests.put( + url=f'https://api.nova-oss.com/users?discord_id={account["auth"]["discord"]}', + timeout=3, + headers={ + 'Content-Type': 'application/json', + 'Authorization': os.getenv('CORE_API_KEY') + }, + data=json.dumps(account) + ) + + except Exception as exc: + await embedder.error(interaction, """Sorry, there was an error while setting your credits. +Please report this issue to the staff!""", ephemeral=True) + raise exc + + await embedder.ok(interaction, f"""Successfully set the credits of {user.name} to **{amount}**.""", ephemeral=True) diff --git a/cord/bot.py b/cord/bot.py index b0cff2e..d1b0e05 100644 --- a/cord/bot.py +++ b/cord/bot.py @@ -79,6 +79,10 @@ async def credits_(interaction: nextcord.Interaction): async def credits_of(interaction: nextcord.Interaction, user: nextcord.User): return await accounts.get_credits_of(interaction, user) +@bot.slash_command(description='Manually set the credits of a certain user. Admin only.') +async def set_credits(interaction: nextcord.Interaction, user: nextcord.User, amount: int): + return await accounts.set_credits(interaction, user, amount) + @bot.slash_command(description='View examples and tips for implementing NovaAI\'s API.') async def tutorial(interaction: nextcord.Interaction, how_can_i: str = SlashOption(#