tux.cogs.utility
¶
Modules:
Name | Description |
---|---|
afk | |
ping | |
poll | |
remindme | |
run | |
self_timeout | |
tldr | |
wiki | |
Functions:
Name | Description |
---|---|
add_afk | Sets a member as AFK, updates their nickname, and saves to the database. |
del_afk | Removes a member's AFK status, restores their nickname, and updates the database. |
Classes¶
Functions¶
_generate_afk_nickname(display_name: str) -> str
¶
Generates the AFK nickname, handling truncation if necessary.
Source code in tux/cogs/utility/__init__.py
Python
def _generate_afk_nickname(display_name: str) -> str:
"""Generates the AFK nickname, handling truncation if necessary."""
prefix_len = len(CONST.AFK_PREFIX)
if len(display_name) >= CONST.NICKNAME_MAX_LENGTH - prefix_len:
suffix_len = len(CONST.AFK_TRUNCATION_SUFFIX)
available_space = CONST.NICKNAME_MAX_LENGTH - prefix_len - suffix_len
truncated_name = f"{display_name[:available_space]}{CONST.AFK_TRUNCATION_SUFFIX}"
return f"{CONST.AFK_PREFIX}{truncated_name}"
return f"{CONST.AFK_PREFIX}{display_name}"
add_afk(db: DatabaseController, reason: str, target: discord.Member, guild_id: int, is_perm: bool, until: datetime | NoneType | None = None, enforced: bool = False) -> None
async
¶
Sets a member as AFK, updates their nickname, and saves to the database.
Source code in tux/cogs/utility/__init__.py
Python
async def add_afk(
db: DatabaseController,
reason: str,
target: discord.Member,
guild_id: int,
is_perm: bool,
until: datetime | NoneType | None = None,
enforced: bool = False,
) -> None:
"""Sets a member as AFK, updates their nickname, and saves to the database."""
new_name = _generate_afk_nickname(target.display_name)
await db.afk.set_afk(target.id, target.display_name, reason, guild_id, is_perm, until, enforced)
# Suppress Forbidden errors if the bot doesn't have permission to change the nickname
with contextlib.suppress(discord.Forbidden):
await target.edit(nick=new_name)
del_afk(db: DatabaseController, target: discord.Member, nickname: str) -> None
async
¶
Removes a member's AFK status, restores their nickname, and updates the database.
Source code in tux/cogs/utility/__init__.py
Python
async def del_afk(db: DatabaseController, target: discord.Member, nickname: str) -> None:
"""Removes a member's AFK status, restores their nickname, and updates the database."""
await db.afk.remove_afk(target.id)
# Suppress Forbidden errors if the bot doesn't have permission to change the nickname
with contextlib.suppress(discord.Forbidden):
# Only attempt to restore nickname if it was actually changed by add_afk
# Prevents resetting a manually changed nickname if del_afk is called unexpectedly
if target.display_name.startswith(CONST.AFK_PREFIX):
await target.edit(nick=nickname)