Skip to content

Commit

Permalink
Merge pull request #642 from allthingslinux/tess-remove-afk
Browse files Browse the repository at this point in the history
feat(clearafk): Add a command to clear another user's AFK status
  • Loading branch information
kzndotsh authored Nov 4, 2024
2 parents fff364c + f0527bb commit ec0c2e7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tux/cogs/moderation/clearafk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import contextlib

import discord
from discord.ext import commands

from tux.bot import Tux
from tux.database.controllers import AfkController
from tux.utils import checks


class ClearAFK(commands.Cog):
def __init__(self, bot: Tux) -> None:
self.bot = bot
self.db = AfkController()
self.clear_afk.usage = "clearafk <member>"

@commands.hybrid_command(
name="clearafk",
aliases=["cafk", "removeafk"],
description="Clear a member's AFK status and reset their nickname.",
)
@commands.guild_only()
@checks.has_pl(2) # Ensure the user has the required permission level
async def clear_afk(
self,
ctx: commands.Context[Tux],
member: discord.Member,
) -> discord.Message:
"""
Clear a member's AFK status and reset their nickname.
Parameters
----------
ctx : commands.Context[Tux]
The context in which the command is being invoked.
member : discord.Member
The member whose AFK status is to be cleared.
"""

assert ctx.guild

if not await self.db.is_afk(member.id, guild_id=ctx.guild.id):
return await ctx.send(f"{member.mention} is not currently AFK.", ephemeral=True)

# Fetch the AFK entry to retrieve the original nickname
entry = await self.db.get_afk_member(member.id, guild_id=ctx.guild.id)

await self.db.remove_afk(member.id)

if entry and entry.nickname:
with contextlib.suppress(discord.Forbidden):
await member.edit(nick=entry.nickname) # Reset nickname to original

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


async def setup(bot: Tux) -> None:
await bot.add_cog(ClearAFK(bot))

0 comments on commit ec0c2e7

Please sign in to comment.