Skip to content

Commit 402986b

Browse files
authored
Merge pull request #821 from allthingslinux/self_timeout
fix(afk): misc fixes for self-timeout
2 parents a2f8a70 + 1fe2b4e commit 402986b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

tux/cogs/moderation/clearafk.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ async def clear_afk(
4747

4848
await self.db.remove_afk(member.id)
4949

50-
if entry and entry.nickname:
51-
with contextlib.suppress(discord.Forbidden):
52-
await member.edit(nick=entry.nickname) # Reset nickname to original
50+
if entry:
51+
if entry.nickname:
52+
with contextlib.suppress(discord.Forbidden):
53+
await member.edit(nick=entry.nickname) # Reset nickname to original
54+
if entry.enforced: # untimeout the user if the afk status is a self-timeout
55+
await member.timeout(None, reason="removing self-timeout")
5356

5457
return await ctx.send(f"AFK status for {member.mention} has been cleared.", ephemeral=True)
5558

tux/cogs/utility/afk.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ async def check_afk(self, message: discord.Message) -> None:
152152
if message.author.bot:
153153
return
154154

155+
# Check if the message is a self-timeout command.
156+
# if it is, the member is probably trying to upgrade to a self-timeout, so AFK status should not be removed.
157+
if message.content.startswith("$sto"):
158+
return
159+
155160
afks_mentioned: list[tuple[discord.Member, AFKModel]] = []
156161

157162
for mentioned in message.mentions:

tux/cogs/utility/self_timeout.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async def self_timeout(self, ctx: commands.Context[Tux], duration: str, *, reaso
4646
duration_seconds: int = convert_to_seconds(duration)
4747
duration_readable = seconds_to_human_readable(duration_seconds)
4848

49+
if duration_seconds == 0:
50+
await ctx.reply("Error! Invalid time format", ephemeral=True)
51+
return
52+
4953
if duration_seconds > 604800:
5054
await ctx.reply("Error! duration cannot be longer than 7 days!", ephemeral=True)
5155
return

0 commit comments

Comments
 (0)