Add multiple username match message on unban, fix len(filter) error

This commit is contained in:
Zeva Rose 2021-07-03 18:08:29 -06:00
parent 5e7b46e0e8
commit 65c6bf5996

View file

@ -195,12 +195,26 @@ class AdminCog(commands.Cog):
bans, bans,
) )
else: else:
results = filter(lambda x: x.user.name == user, bans) results = [
x for x in filter(lambda x: x.user.name == user, bans)
]
if results: if results:
if len(results) > 1: if len(results) > 1:
# TODO: send list of bans that matched active_bans = []
# for admins to use on next attempt for ban in bans:
pass active_bans.append(
"{0} ({1}): {2}".format(
ban.user.name, ban.user.id, ban.reason
)
)
message = (
"More than one result. "
+ "Please use one of the following IDs:\n```"
+ "\n".join(active_bans)
+ "\n```"
)
await ctx.send(message)
return
else: else:
discord_ban_info = results[0] discord_ban_info = results[0]
@ -308,7 +322,7 @@ class AdminCog(commands.Cog):
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]"
ban_messages.append( ban_messages.append(
"[{0}] {1} ({2}): {3}\n".format( "[{0}] {1} ({2}): {3}".format(
ban["time"].strftime("%d-%m-%Y"), ban["time"].strftime("%d-%m-%Y"),
ban["username"], ban["username"],
ban["user"], ban["user"],