fix (timers): Correct permissions for stop.

This commit is contained in:
2023-08-27 08:23:36 +03:00
parent 38ba7f1ded
commit 7a40ca2cea
2 changed files with 43 additions and 6 deletions

View File

@@ -305,6 +305,8 @@ class Timer:
role = TimerRole.ADMIN role = TimerRole.ADMIN
elif member.id == self.data.ownerid: elif member.id == self.data.ownerid:
role = TimerRole.OWNER role = TimerRole.OWNER
elif self.channel and self.channel.permissions_for(member).manage_channels:
role = TimerRole.MANAGER
elif (roleid := self.data.manager_roleid) and roleid in (r.id for r in member.roles): elif (roleid := self.data.manager_roleid) and roleid in (r.id for r in member.roles):
role = TimerRole.MANAGER role = TimerRole.MANAGER
else: else:

View File

@@ -78,7 +78,8 @@ class TimerStatusUI(LeoUI):
t = self.bot.translator.t t = self.bot.translator.t
error_msg = t(_p( error_msg = t(_p(
'ui:timer_status|button:edit|error:no_permissions', 'ui:timer_status|button:edit|error:no_permissions',
"Configuring this timer requires guild admin permissions or the configured manager role!" "Configuring this timer requires `MANAGE_CHANNEL` permissions on "
"the timer channel, or the configured manager role!"
)) ))
embed = discord.Embed( embed = discord.Embed(
colour=discord.Colour.brand_red(), colour=discord.Colour.brand_red(),
@@ -114,9 +115,25 @@ class TimerStatusUI(LeoUI):
ephemeral=True ephemeral=True
) )
else: else:
role = self.timer.get_member_role(press.user)
if role >= TimerRole.MANAGER or self.timer.auto_restart:
# Start the timer # Start the timer
await press.response.defer() await press.response.defer()
await self.timer.start() await self.timer.start()
else:
embed = discord.Embed(
colour=discord.Colour.brand_red(),
title=t(_p(
'ui:timer_status|button:start|error:not_manager|title',
"Insufficient permissions!"
)),
description=t(_p(
'ui:timer_status|button:start|error:not_manager|desc',
"Starting this timer requires `MANAGE_CHANNEL` permissions on "
"the timer channel, or the configured `manager_role`!"
))
)
await press.response.send_message(embed=embed, ephemeral=True)
async def refresh_start_button(self): async def refresh_start_button(self):
t = self.bot.translator.t t = self.bot.translator.t
@@ -132,8 +149,26 @@ class TimerStatusUI(LeoUI):
Note that unlike starting, stopping is allowed to be idempotent. Note that unlike starting, stopping is allowed to be idempotent.
""" """
t = self.bot.translator.t
role = self.timer.get_member_role(press.user)
if role >= TimerRole.MANAGER:
# Stop the timer
await press.response.defer() await press.response.defer()
await self.timer.stop() await self.timer.stop()
else:
embed = discord.Embed(
colour=discord.Colour.brand_red(),
title=t(_p(
'ui:timer_status|button:stop|error:not_manager|title',
"Insufficient permissions!"
)),
description=t(_p(
'ui:timer_status|button:stop|error:not_manager|desc',
"Stopping this timer requires `MANAGE_CHANNEL` permissions on "
"the timer channel, or the configured `manager_role`!"
))
)
await press.response.send_message(embed=embed, ephemeral=True)
async def refresh_stop_button(self): async def refresh_stop_button(self):
t = self.bot.translator.t t = self.bot.translator.t