feat(shard): ✨ Store unbanner.
This commit is contained in:
+9
-2
@@ -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}")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
version = 1
|
||||
revision = 1
|
||||
requires-python = ">=3.12"
|
||||
|
||||
[[package]]
|
||||
@@ -128,7 +127,7 @@ version = "8.1.8"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "anyio" },
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "colorama", marker = "platform_system == 'Windows'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cb/b5/e1e5fdf1c1bb7e6e614987c120a98d9324bf8edfaa5f5cd16a6235c9d91b/asyncclick-8.1.8.tar.gz", hash = "sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c", size = 232900 }
|
||||
wheels = [
|
||||
@@ -189,7 +188,7 @@ name = "click"
|
||||
version = "8.1.8"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "colorama", marker = "platform_system == 'Windows'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 }
|
||||
wheels = [
|
||||
@@ -405,7 +404,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "payphone"
|
||||
version = "0.42.0"
|
||||
version = "0.43.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "aerich" },
|
||||
|
||||
Reference in New Issue
Block a user