feat(shard): ✨ Store unbanner.

This commit is contained in:
2025-03-16 00:01:04 -03:00
parent 515048f43d
commit 0067481528
4 changed files with 29 additions and 10 deletions
+9 -2
View File
@@ -304,14 +304,21 @@ class Payphone(commands.AutoShardedBot):
return ban
async def unban(self, user_id: int) -> None:
async def unban(self, user_id: int, expired_by: int | None) -> None:
"""Unbans a user.
Args:
user_id (int): The user to unban's ID.
expired_by (int | None): The user who expired the ban.
"""
await models.Ban.filter(user_id=user_id).delete()
await models.Ban.filter(
(
expressions.Q(expires_at__gt=datetime.now(timezone.utc))
| expressions.Q(expires_at=None)
)
& expressions.Q(user_id=user_id)
).update(expires_at=datetime.now(timezone.utc), expired_by_id=expired_by)
await self.redis.delete(f"banned:{user_id}")
+16 -3
View File
@@ -84,7 +84,7 @@ class Admin(base.Cog):
user = user or ctx.author
await self.bot.unban(user.id)
await self.bot.unban(user.id, ctx.author.id)
await ctx.send(f"{user.mention} was unbanned from Payphone.")
@@ -163,7 +163,7 @@ class Admin(base.Cog):
bans = (
await models.Ban.filter(user_id=user_id)
.prefetch_related("report", "created_by")
.prefetch_related("report", "created_by", "expired_by")
.order_by("-created_at")
)
@@ -209,13 +209,26 @@ class Admin(base.Cog):
thumbnail=ban.report.user_avatar_url,
footer=discord.EmbedFooter(
text=f"Banned by {(await self.bot.get_or_fetch_user(ban.created_by.id)).display_name}"
+ (
f" · Unbanned by {(await self.bot.get_or_fetch_user(ban.expired_by.id)).display_name}"
if ban.expired_by
else ""
)
),
)
if ban.report
else discord.Embed(
color=constants.PRIMARY_COLOR,
title=f"Ban #{ban.id}",
description=f"The user was banned manually by <@!{ban.created_by.id}> <t:{int(ban.created_at.timestamp())}:R>.",
description=f"The user was banned manually by <@!{ban.created_by.id}> <t:{int(ban.created_at.timestamp())}:R>. It expires {f"<t:{int(ban.expires_at.timestamp())}:R>" if ban.expires_at else "never"}.",
footer=discord.EmbedFooter(
text=f"Banned by {(await self.bot.get_or_fetch_user(ban.created_by.id)).display_name}"
+ (
f" · Unbanned by {(await self.bot.get_or_fetch_user(ban.expired_by.id)).display_name}"
if ban.expired_by
else ""
)
),
)
)
for ban in bans
+1 -1
View File
@@ -149,7 +149,7 @@ class Ban(models.Model):
created_at = fields.DatetimeField(auto_now_add=True)
expires_at = fields.DatetimeField(null=True)
created_by = fields.ForeignKeyField("models.User", related_name="created_bans")
expired_by = fields.ForeignKeyField("models.User", related_name="bans", null=True)
expired_by = fields.ForeignKeyField("models.User", related_name="expired_bans", null=True)
class Meta:
"""