diff --git a/payphone/cogs/admin/cog.py b/payphone/cogs/admin/cog.py index a9a740e..a1ed515 100644 --- a/payphone/cogs/admin/cog.py +++ b/payphone/cogs/admin/cog.py @@ -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: models.User | None = await models.User.get_or_none(id=user_id) + + if user is None: + return await ctx.send("❌ User not found.") + bans = ( await models.Ban.filter(user_id=user_id) .prefetch_related("report", "created_by", "expired_by") .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: - await ctx.send(f"<@!{user_id}> has no bans.") + if not bans and not warns: + 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 - await pages.Paginator( - [ - ( - discord.Embed( - color=constants.MODERATOR_COLOR, - title=f"Ban #{ban.id}", - description=formatting.trim(ban.report.message_content, 500), - author=discord.EmbedAuthor( - name=ban.report.user_name, - icon_url=ban.report.user_avatar_url, + ban_embeds = [ + ( + discord.Embed( + color=constants.MODERATOR_COLOR, + title=f"Ban #{ban.id}", + description=formatting.trim(ban.report.message_content, 500), + author=discord.EmbedAuthor( + name=ban.report.user_name, + icon_url=ban.report.user_avatar_url, + ), + fields=[ + discord.EmbedField( + name="Banned Until", + value=( + f" ()" + 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( - name="Banned Until", - value=( - f" ()" - if ban.expires_at - else "Forever" - ), - ), - discord.EmbedField( - name="User Avatar", - value=f"[Click to open avatar URL](<{ban.report.user_avatar_url}>)", - ), + name="Replying To", + 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}" + ( - [ - discord.EmbedField( - name="Replying To", - 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}> . {(f"It expires " if not ban.is_expired else f"It expired ") 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 "" - ) - ), - ) + 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}> . {(f"It expires " if not ban.is_expired else f"It expired ") 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}> .", + 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, ).send(ctx)