From b0d5b8a5f7f4692e92a84827500a2ef28de89333 Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:40:45 -0300 Subject: [PATCH] feat(bot): :sparkles: Add past bans to `p.user`. --- payphone/cogs/mods/cog.py | 28 +++++++++++++++++----------- payphone/core/formatting.py | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/payphone/cogs/mods/cog.py b/payphone/cogs/mods/cog.py index 04c35d2..75415fd 100644 --- a/payphone/cogs/mods/cog.py +++ b/payphone/cogs/mods/cog.py @@ -451,7 +451,7 @@ class Mods(base.Cog): bans = await models.Ban.filter( user_id=user_id, - ) + ).order_by("-created_at") ongoing_bans = [ ban @@ -476,21 +476,27 @@ class Mods(base.Cog): fields=[ discord.EmbedField( name="Ongoing Bans", - value="\n".join( - [ - f"- `ID: {ban.id}`{f" (by <@{ban.banned_by_id}>)" if ban.banned_by_id else None}: {ban.reason if ban.reason else "*No reason*"}. Banned {f"until " if ban.expires_at is not None else "permanently"}." - for ban in ongoing_bans - ] + value=fmt.trim( + "\n".join( + [ + f"- `ID: {ban.id}`{f" (by <@{ban.banned_by_id}>)" if ban.banned_by_id else None}: {ban.reason if ban.reason else "*No reason*"}. Banned {f"until " if ban.expires_at is not None else "permanently"}." + for ban in ongoing_bans + ] + ), + 1024, ) or "*No ongoing bans.*", ), discord.EmbedField( name="Past Bans", - value="\n".join( - [ - f"- `ID: {ban.id}`{f" (by <@{ban.banned_by_id}>)" if ban.banned_by_id else None}: {ban.reason if ban.reason else "*No reason*"}. {"Expired" if ban.unbanned_by_id is None else f"Unbanned by <@{ban.unbanned_by_id}>"} ." - for ban in expired_bans - ] + value=fmt.trim( + "\n".join( + [ + f"- `ID: {ban.id}`{f" (by <@{ban.banned_by_id}>)" if ban.banned_by_id else None}: {ban.reason if ban.reason else "*No reason*"}. {"Expired" if ban.unbanned_by_id is None else f"Unbanned by <@{ban.unbanned_by_id}>"} ." + for ban in expired_bans + ] + ), + 1024, ) or "*No expired bans.*", ), diff --git a/payphone/core/formatting.py b/payphone/core/formatting.py index 5035c00..e7a893f 100644 --- a/payphone/core/formatting.py +++ b/payphone/core/formatting.py @@ -20,7 +20,7 @@ def trim(text: str, length: int = 100) -> str: """ if len(text) > length: - return text[:length] + "..." + return text[:length - 3] + "..." return text