Skip to content

Commit

Permalink
Fix permission check in /selftimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
viotalJiplk committed May 29, 2023
1 parent 2e2f9e6 commit 5e8e576
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions cogs/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5e8e576

Please sign in to comment.