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(
|
bans = self.db.jarvis.bans.find(search).sort(
|
||||||
[("time", pymongo.DESCENDING)]
|
[("time", pymongo.DESCENDING)]
|
||||||
)
|
)
|
||||||
message = "Bans:\n```\n"
|
ban_messages = []
|
||||||
db_bans = []
|
db_bans = []
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
if "username" not in ban:
|
if "username" not in ban:
|
||||||
user = await self.bot.fetch_user(ban["user"])
|
user = await self.bot.fetch_user(ban["user"])
|
||||||
ban["username"] = user.name if user else "[deleted user]"
|
ban["username"] = user.name if user else "[deleted user]"
|
||||||
message += "[{0}] {1} ({2}): {3}\n".format(
|
ban_messages.append(
|
||||||
ban["time"].strftime("%d-%m-%Y"),
|
"[{0}] {1} ({2}): {3}\n".format(
|
||||||
ban["username"],
|
ban["time"].strftime("%d-%m-%Y"),
|
||||||
ban["user"],
|
ban["username"],
|
||||||
ban["reason"],
|
ban["user"],
|
||||||
|
ban["reason"],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
bans = await ctx.guild.bans()
|
bans = await ctx.guild.bans()
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
if ban.user.id not in db_bans:
|
if ban.user.id not in db_bans:
|
||||||
message += "[unknown] {0} ({1}): {2}".format(
|
ban_messages.append(
|
||||||
ban.user.name, ban.user.id, ban.reason
|
"[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)
|
await ctx.send(message)
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
@cog_ext.cog_slash(
|
||||||
|
|
Loading…
Add table
Reference in a new issue