From c9ea838d5d53cd212efdd64b13b09fafd80b63d5 Mon Sep 17 00:00:00 2001 From: henceiusegentoo Date: Tue, 8 Aug 2023 14:27:31 +0200 Subject: [PATCH] Added a Admin-Only command for admins (Maintainers) to see the credits of other users --- cord/accounts.py | 24 ++++++++++++++++++++++++ cord/bot.py | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/cord/accounts.py b/cord/accounts.py index 3aef13d..506e9b9 100644 --- a/cord/accounts.py +++ b/cord/accounts.py @@ -57,3 +57,27 @@ async def get_credits(interaction): await embedder.info(interaction, f"""### Your credits Amount: **{amount_credits if amount_credits < 1000000 else '∞'}** """, ephemeral=True) + +async def get_credits_of(interaction, user): + if "Maintainer" not in interaction.user.roles: + 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() + amount_credits = account["credits"] + + await embedder.info(interaction, f"""### Credits of {user.name} +Amount: **{amount_credits if amount_credits < 1000000 else '∞'}** +""", ephemeral=True) \ No newline at end of file diff --git a/cord/bot.py b/cord/bot.py index 7b29cd3..b0cff2e 100644 --- a/cord/bot.py +++ b/cord/bot.py @@ -75,6 +75,10 @@ async def account(interaction: nextcord.Interaction): async def credits_(interaction: nextcord.Interaction): return await accounts.get_credits(interaction) +@bot.slash_command(description='Get credits of a certain user. Admin only.') +async def credits_of(interaction: nextcord.Interaction, user: nextcord.User): + return await accounts.get_credits_of(interaction, user) + @bot.slash_command(description='View examples and tips for implementing NovaAI\'s API.') async def tutorial(interaction: nextcord.Interaction, how_can_i: str = SlashOption(#