Skip to content

Commit

Permalink
Merge pull request #641 from allthingslinux/tess-afk-limit
Browse files Browse the repository at this point in the history
Limit the amount of characters /afk can use
  • Loading branch information
kzndotsh authored Nov 4, 2024
2 parents ec0c2e7 + a63872a commit b06ec98
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tux/cogs/utility/afk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import contextlib
import textwrap
from datetime import datetime, timedelta
from typing import cast
from zoneinfo import ZoneInfo

import discord
Expand Down Expand Up @@ -53,13 +55,14 @@ async def afk(
else:
new_name = f"[AFK] {target.display_name}"

await self.db.insert_afk(target.id, target.display_name, reason, ctx.guild.id)
shortened_reason = textwrap.shorten(reason, width=100, placeholder="...")
await self.db.insert_afk(target.id, target.display_name, shortened_reason, ctx.guild.id)

with contextlib.suppress(discord.Forbidden):
await target.edit(nick=new_name)

return await ctx.send(
content="\N{SLEEPING SYMBOL} || You are now afk! " + f"Reason: `{reason}`",
content="\N{SLEEPING SYMBOL} || You are now afk! " + f"Reason: `{shortened_reason}`",
allowed_mentions=discord.AllowedMentions(
users=False,
everyone=False,
Expand Down Expand Up @@ -114,19 +117,19 @@ async def check_afk(self, message: discord.Message) -> None:
if message.author.bot:
return

afks_mentioned: list[AFKModel] = []
afks_mentioned: list[tuple[discord.Member, AFKModel]] = []

for mentioned in message.mentions:
entry = await self.db.get_afk_member(mentioned.id, guild_id=message.guild.id)
if entry:
afks_mentioned.append(entry)
afks_mentioned.append((cast(discord.Member, mentioned), entry))

if not afks_mentioned:
return

msgs: list[str] = [
f"{mentioned.mention} is currently AFK: `{afk.reason}` (<t:{int(afk.since.timestamp())}:R>)"
for mentioned, afk in zip(message.mentions, afks_mentioned, strict=False)
for mentioned, afk in afks_mentioned
]

await message.reply(
Expand Down

0 comments on commit b06ec98

Please sign in to comment.