feat(shard): ✨ Show warns in the p.bs command.
This commit is contained in:
+132
-64
@@ -191,83 +191,151 @@ class Admin(base.Cog):
|
|||||||
|
|
||||||
user_id = user if isinstance(user, int) else user.id if user else ctx.author.id
|
user_id = user if isinstance(user, int) else user.id if user else ctx.author.id
|
||||||
|
|
||||||
|
user: models.User | None = await models.User.get_or_none(id=user_id)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
return await ctx.send("❌ User not found.")
|
||||||
|
|
||||||
bans = (
|
bans = (
|
||||||
await models.Ban.filter(user_id=user_id)
|
await models.Ban.filter(user_id=user_id)
|
||||||
.prefetch_related("report", "created_by", "expired_by")
|
.prefetch_related("report", "created_by", "expired_by")
|
||||||
.order_by("-created_at")
|
.order_by("-created_at")
|
||||||
)
|
)
|
||||||
|
warns = (
|
||||||
|
await models.Warn.filter(user_id=user_id)
|
||||||
|
.prefetch_related("report", "created_by")
|
||||||
|
.order_by("-created_at")
|
||||||
|
)
|
||||||
|
|
||||||
if not bans:
|
if not bans and not warns:
|
||||||
await ctx.send(f"<@!{user_id}> has no bans.")
|
if user.bans_count or user.warns_count:
|
||||||
|
await ctx.send(
|
||||||
|
"<@!{user_id}> has no bans nor warns registered in the database, but they"
|
||||||
|
f" have been banned `{user.bans_count}` times and warned `{user.warns_count}`."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
await ctx.send(f"<@!{user_id}> has no bans nor warns.")
|
||||||
return
|
return
|
||||||
|
|
||||||
await pages.Paginator(
|
ban_embeds = [
|
||||||
[
|
(
|
||||||
(
|
discord.Embed(
|
||||||
discord.Embed(
|
color=constants.MODERATOR_COLOR,
|
||||||
color=constants.MODERATOR_COLOR,
|
title=f"Ban #{ban.id}",
|
||||||
title=f"Ban #{ban.id}",
|
description=formatting.trim(ban.report.message_content, 500),
|
||||||
description=formatting.trim(ban.report.message_content, 500),
|
author=discord.EmbedAuthor(
|
||||||
author=discord.EmbedAuthor(
|
name=ban.report.user_name,
|
||||||
name=ban.report.user_name,
|
icon_url=ban.report.user_avatar_url,
|
||||||
icon_url=ban.report.user_avatar_url,
|
),
|
||||||
|
fields=[
|
||||||
|
discord.EmbedField(
|
||||||
|
name="Banned Until",
|
||||||
|
value=(
|
||||||
|
f"<t:{int(ban.expires_at.timestamp())}> (<t:{int(ban.expires_at.timestamp())}:R>)"
|
||||||
|
if ban.expires_at
|
||||||
|
else "Forever"
|
||||||
|
),
|
||||||
),
|
),
|
||||||
fields=[
|
discord.EmbedField(
|
||||||
|
name="User Avatar",
|
||||||
|
value=f"[Click to open avatar URL](<{ban.report.user_avatar_url}>)",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
+ (
|
||||||
|
[
|
||||||
discord.EmbedField(
|
discord.EmbedField(
|
||||||
name="Banned Until",
|
name="Replying To",
|
||||||
value=(
|
value=f'"{formatting.trim(ban.report.reply_message_content)}" by {ban.report.reply_user_name}',
|
||||||
f"<t:{int(ban.expires_at.timestamp())}> (<t:{int(ban.expires_at.timestamp())}:R>)"
|
)
|
||||||
if ban.expires_at
|
|
||||||
else "Forever"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
discord.EmbedField(
|
|
||||||
name="User Avatar",
|
|
||||||
value=f"[Click to open avatar URL](<{ban.report.user_avatar_url}>)",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
if ban.report.reply_message_content
|
||||||
|
else []
|
||||||
|
),
|
||||||
|
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}"
|
||||||
discord.EmbedField(
|
if ban.expired_by
|
||||||
name="Replying To",
|
else ""
|
||||||
value=f'"{formatting.trim(ban.report.reply_message_content)}" by {ban.report.reply_user_name}',
|
)
|
||||||
)
|
),
|
||||||
]
|
|
||||||
if ban.report.reply_message_content
|
|
||||||
else []
|
|
||||||
),
|
|
||||||
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.MODERATOR_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>. {(f"It expires <t:{int(ban.expires_at.timestamp())}:R>" if not ban.is_expired else f"It expired <t:{int(ban.expires_at.timestamp())}:R>") if ban.expires_at else "It doesn't expire"}.",
|
|
||||||
fields=[
|
|
||||||
discord.EmbedField(
|
|
||||||
name="Reason", value=ban.reason or "No reason provided."
|
|
||||||
)
|
|
||||||
],
|
|
||||||
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
|
if ban.report
|
||||||
],
|
else discord.Embed(
|
||||||
|
color=constants.MODERATOR_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>. {(f"It expires <t:{int(ban.expires_at.timestamp())}:R>" if not ban.is_expired else f"It expired <t:{int(ban.expires_at.timestamp())}:R>") if ban.expires_at else "It doesn't expire"}.",
|
||||||
|
fields=[
|
||||||
|
discord.EmbedField(
|
||||||
|
name="Reason", value=ban.reason or "No reason provided."
|
||||||
|
)
|
||||||
|
],
|
||||||
|
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
|
||||||
|
]
|
||||||
|
|
||||||
|
warn_embeds = [
|
||||||
|
(
|
||||||
|
discord.Embed(
|
||||||
|
color=constants.MASK_COLOR,
|
||||||
|
title=f"Warn #{warn.id}",
|
||||||
|
description=formatting.trim(warn.report.message_content, 500),
|
||||||
|
author=discord.EmbedAuthor(
|
||||||
|
name=warn.report.user_name,
|
||||||
|
icon_url=warn.report.user_avatar_url,
|
||||||
|
),
|
||||||
|
fields=[
|
||||||
|
discord.EmbedField(
|
||||||
|
name="User Avatar",
|
||||||
|
value=f"[Click to open avatar URL](<{warn.report.user_avatar_url}>)",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
+ (
|
||||||
|
[
|
||||||
|
discord.EmbedField(
|
||||||
|
name="Replying To",
|
||||||
|
value=f'"{formatting.trim(warn.report.reply_message_content)}" by {warn.report.reply_user_name}',
|
||||||
|
)
|
||||||
|
]
|
||||||
|
if warn.report.reply_message_content
|
||||||
|
else []
|
||||||
|
),
|
||||||
|
thumbnail=warn.report.user_avatar_url,
|
||||||
|
footer=discord.EmbedFooter(
|
||||||
|
text=f"Warned by {(await self.bot.get_or_fetch_user(warn.created_by.id)).display_name}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if warn.report
|
||||||
|
else discord.Embed(
|
||||||
|
color=constants.MASK_COLOR,
|
||||||
|
title=f"Warn #{warn.id}",
|
||||||
|
description=f"The user was warned manually by <@!{warn.created_by.id}> <t:{int(warn.created_at.timestamp())}:R>.",
|
||||||
|
fields=[
|
||||||
|
discord.EmbedField(
|
||||||
|
name="Reason", value=warn.reason or "No reason provided."
|
||||||
|
)
|
||||||
|
],
|
||||||
|
footer=discord.EmbedFooter(
|
||||||
|
text=f"Warned by {(await self.bot.get_or_fetch_user(warn.created_by.id)).display_name}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for warn in warns
|
||||||
|
]
|
||||||
|
|
||||||
|
await pages.Paginator(
|
||||||
|
ban_embeds + warn_embeds,
|
||||||
author_check=True,
|
author_check=True,
|
||||||
).send(ctx)
|
).send(ctx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user