Skip to content

Commit

Permalink
Update cooldown configuration in shortenUrl and emojify commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingzy committed Feb 5, 2024
1 parent 9eda930 commit a0b77b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 6 additions & 2 deletions cogs/shorten.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def __init__(self, short_code):
password="The password for the URL",
)
@app_commands.guild_only()
@app_commands.checks.cooldown(1, 30.0)
@app_commands.checks.cooldown(1, 10.0)
@app_commands.checks.cooldown(5, 60.0)
@app_commands.checks.cooldown(200, 24*60*60.0)
async def shorten(self, interaction: discord.Interaction, url: str, alias:str = None, max_clicks: int=None, password: str=None ):

await interaction.response.defer()
Expand Down Expand Up @@ -84,7 +86,9 @@ async def shorten(self, interaction: discord.Interaction, url: str, alias:str =
password="The password for the URL",
)
@app_commands.guild_only()
@app_commands.checks.cooldown(1, 30.0)
@app_commands.checks.cooldown(1, 10.0)
@app_commands.checks.cooldown(5, 60.0)
@app_commands.checks.cooldown(200, 24*60*60.0)
async def emojify(self, interaction, url: str, emojies: str = None, max_clicks: int = None, password: str = None):

await interaction.response.defer()
Expand Down
2 changes: 1 addition & 1 deletion cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def stats_error(
self, interaction: discord.Interaction, error: app_commands.AppCommandError
):
if isinstance(error, app_commands.CommandOnCooldown):
embed = await generate_error_message(interaction, error)
embed = await generate_error_message(interaction, error, cooldown_configuration = ["- ```1 time every 30 seconds```"])
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = await generate_command_error_embed(interaction, error, "stats")
Expand Down
23 changes: 12 additions & 11 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,36 +234,37 @@ def make_countries_heatmap(
return plt


async def generate_error_message(interaction: discord.Interaction, error):
async def generate_error_message(interaction: discord.Interaction, error, cooldown_configuration=["- ```1 time every 10 seconds```", "- ```5 times every 60 seconds```", "- ```200 times every 24 hours```"]):
end_time = datetime.datetime.now() + datetime.timedelta(seconds=error.retry_after)
end_time_ts = f"<t:{int(end_time.timestamp())}>"

hours, remainder = divmod(error.retry_after, 3600)
minutes, seconds = divmod(remainder, 60)
seconds = round(seconds)
time_left = f"{seconds} second{'s' if seconds != 1 else ''}"
end_time_ts = int(end_time.timestamp())

embed = discord.Embed(
title="⏳ Cooldown",
description=f"You have to wait until **{end_time_ts}** ({time_left}) to use this command again.",
description=f"### You can use this command again <t:{end_time_ts}:R>",
color=discord.Color.red(),
timestamp=interaction.created_at,
)
embed.set_image(url=random.choice(waiting_gifs))

embed.add_field(
name = "How many times can I use this command?",
value = "\n".join(cooldown_configuration),
inline=False,
)

try:
embed.set_footer(
text=f"Requested by {interaction.user}",
text=f"{interaction.user} used /{interaction.command.name}",
icon_url=interaction.user.avatar,
)
except:
embed.set_footer(
text=f"Requested by {interaction.user}",
text=f"{interaction.user} used /{interaction.command.name}",
icon_url=interaction.user.default_avatar,
)

return embed


async def generate_command_error_embed(
interaction: discord.Interaction, error, command_name
):
Expand Down

0 comments on commit a0b77b7

Please sign in to comment.