Compare commits

...

2 commits

Author SHA1 Message Date
Felix b0334021e9
Merge pull request #2 from unfortunatelyalex/main
Added a "set_credits" command
2023-08-09 18:10:48 +02:00
alex 5540143da9 Added a set_credits command 2023-08-09 11:04:00 +00:00
2 changed files with 42 additions and 0 deletions

View file

@ -81,3 +81,41 @@ Please report this issue to the staff!""", ephemeral=True)
await embedder.info(interaction, f"""### Credits of {user.name} await embedder.info(interaction, f"""### Credits of {user.name}
Amount: **{amount_credits if amount_credits < 1000000 else ''}** Amount: **{amount_credits if amount_credits < 1000000 else ''}**
""", ephemeral=True) """, 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)

View file

@ -79,6 +79,10 @@ async def credits_(interaction: nextcord.Interaction):
async def credits_of(interaction: nextcord.Interaction, user: nextcord.User): async def credits_of(interaction: nextcord.Interaction, user: nextcord.User):
return await accounts.get_credits_of(interaction, 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.') @bot.slash_command(description='View examples and tips for implementing NovaAI\'s API.')
async def tutorial(interaction: nextcord.Interaction, async def tutorial(interaction: nextcord.Interaction,
how_can_i: str = SlashOption(# how_can_i: str = SlashOption(#