From 5e8e576b89e1430bc0a17b6dd97fb37e2990920b Mon Sep 17 00:00:00 2001 From: viotalJiplk Date: Mon, 29 May 2023 23:05:13 +0200 Subject: [PATCH] Fix permission check in /selftimeout --- cogs/timeout.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/cogs/timeout.py b/cogs/timeout.py index 9256eb4d..a97e3011 100644 --- a/cogs/timeout.py +++ b/cogs/timeout.py @@ -123,6 +123,7 @@ async def timeout_parse(self, inter, user, endtime, reason, isself=False): convert to timedelta returns endtime: class datetime + or None in case of insufficient permissions """ # convert to local time and remove timezone info @@ -289,6 +290,31 @@ async def timeout_list( await self.timeout_embed_listing(users, "Timeout list", inter, inter.author) + @cooldowns.default_cooldown + @commands.slash_command( + name="selftimeout", + description=Messages.self_timeout, + guild_ids=[config.guild_id] + ) + async def self_timeout( + self, + inter: disnake.ApplicationCommandInteraction, + endtime: str = commands.Param( + autocomplete=autocomplete_times, + max_length=20, description=Messages.timeout_time + ) + ): + # Guild_id is used to prevent users from bypassing timeout + # given by moderator and using selftimeout in DMs + + await inter.response.defer(ephemeral=True) + + if await self.timeout_parse(inter, inter.user, endtime, Messages.self_timeout_reason, True) is None: + await inter.send(content=Messages.timeout_permission.format(user=inter.user)) + self.perms_users = [] + return + await inter.send(content=Messages.self_timeout_success) + async def update_timeout(self): """update all user's timeout in database and on server""" users = self.timeout_repo.get_timeout_users() @@ -344,28 +370,6 @@ async def on_audit_log_entry_create(self, entry): await self.submod_helper_room.send(embed=embed) - @cooldowns.default_cooldown - @commands.slash_command( - name="selftimeout", - description=Messages.self_timeout, - guild_ids=[config.guild_id] - ) - async def self_timeout( - self, - inter: disnake.ApplicationCommandInteraction, - endtime: str = commands.Param( - autocomplete=autocomplete_times, - max_length=20, description=Messages.timeout_time - ) - ): - # Guild_id is used to prevent users from bypassing timeout - # given by moderator and using selftimeout in DMs - - await inter.response.defer(ephemeral=True) - - await self.timeout_parse(inter, inter.user, endtime, Messages.self_timeout_reason, True) - await inter.send(content=Messages.self_timeout_success) - @self_timeout.error @timeout_user.error async def timeout_error(self, inter: disnake.ApplicationCommandInteraction, error):