Smarter handling of bans list message
This commit is contained in:
parent
bb85958d75
commit
a62c42042e
1 changed files with 17 additions and 9 deletions
|
@ -300,25 +300,33 @@ class AdminCog(commands.Cog):
|
|||
bans = self.db.jarvis.bans.find(search).sort(
|
||||
[("time", pymongo.DESCENDING)]
|
||||
)
|
||||
message = "Bans:\n```\n"
|
||||
ban_messages = []
|
||||
db_bans = []
|
||||
for ban in bans:
|
||||
if "username" not in ban:
|
||||
user = await self.bot.fetch_user(ban["user"])
|
||||
ban["username"] = user.name if user else "[deleted user]"
|
||||
message += "[{0}] {1} ({2}): {3}\n".format(
|
||||
ban["time"].strftime("%d-%m-%Y"),
|
||||
ban["username"],
|
||||
ban["user"],
|
||||
ban["reason"],
|
||||
ban_messages.append(
|
||||
"[{0}] {1} ({2}): {3}\n".format(
|
||||
ban["time"].strftime("%d-%m-%Y"),
|
||||
ban["username"],
|
||||
ban["user"],
|
||||
ban["reason"],
|
||||
)
|
||||
)
|
||||
bans = await ctx.guild.bans()
|
||||
for ban in bans:
|
||||
if ban.user.id not in db_bans:
|
||||
message += "[unknown] {0} ({1}): {2}".format(
|
||||
ban.user.name, ban.user.id, ban.reason
|
||||
ban_messages.append(
|
||||
"[unknown] {0} ({1}): {2}".format(
|
||||
ban.user.name, ban.user.id, ban.reason
|
||||
)
|
||||
)
|
||||
message += "```"
|
||||
message = ""
|
||||
if len(ban_messages) == 0:
|
||||
message = "No bans matched the criteria."
|
||||
else:
|
||||
message = "Bans:\n```\n" + "\n".join(ban_messages) + "\n```"
|
||||
await ctx.send(message)
|
||||
|
||||
@cog_ext.cog_slash(
|
||||
|
|
Loading…
Add table
Reference in a new issue