From 8d090c5c674380b59155eae9ae3ca6f46b043818 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 9 Apr 2022 21:58:34 -0400 Subject: [PATCH] //WIP v3 Clear Messages Changes - Better logging - Better output --- modules/ClearChannelMessages/cog.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/ClearChannelMessages/cog.py b/modules/ClearChannelMessages/cog.py index ed55ee4..df23fe4 100644 --- a/modules/ClearChannelMessages/cog.py +++ b/modules/ClearChannelMessages/cog.py @@ -1,6 +1,5 @@ import logging from discord.ext import commands -import asyncio LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop") @@ -12,17 +11,24 @@ class ClearMessages(commands.Cog): @commands.command() async def clear(self, ctx, amount=0): member = ctx.author.display_name + mtn_member = f"<@{member}>" LOGGER.info(f"Clear {amount} messages requested by {member}") - authors = {} - async for message in ctx.channel.history(limit=amount + 1): + authors = {} + async for message in ctx.channel.history(limit=amount): if message.author not in authors: authors[message.author] = 1 else: authors[message.author] += 1 await message.delete() - msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()]) + msg = f"{mtn_member}, I deleted {sum(authors.values())} messages\n" + LOGGER.debug(f"Deleted {sum(authors.values())} messages from {ctx.message.channel}") + + for author in authors.keys(): + msg += f"\t{author}: {authors[author]}" + LOGGER.debug(f"Deleted {authors[author]} messages from {author}") + await ctx.channel.send(msg)