diff --git a/modules/ClearChannelMessages/cog.py b/modules/ClearChannelMessages/cog.py index e902035..ed55ee4 100644 --- a/modules/ClearChannelMessages/cog.py +++ b/modules/ClearChannelMessages/cog.py @@ -1,6 +1,9 @@ +import logging from discord.ext import commands import asyncio +LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop") + class ClearMessages(commands.Cog): def __init__(self, bot): @@ -8,23 +11,19 @@ class ClearMessages(commands.Cog): @commands.command() async def clear(self, ctx, amount=0): - if amount == 0: - fail = await ctx.send("Please enter an amount to delete!") - await asyncio.sleep(6) - await fail.delete() + member = ctx.author.display_name + LOGGER.info(f"Clear {amount} messages requested by {member}") + authors = {} - if amount < 3: - await ctx.channel.purge(limit=amount) - sucess = await ctx.send( - f"{amount} messages has been deleted ") # sending success msg - await asyncio.sleep(6) # wait 6 seconds - await sucess.delete() # deleting the success msg + async for message in ctx.channel.history(limit=amount + 1): + if message.author not in authors: + authors[message.author] = 1 + else: + authors[message.author] += 1 + await message.delete() - else: - if amount == 0: - fail = await ctx.send("Please enter an amount to delete!") - await asyncio.sleep(6) - await fail.delete() + msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()]) + await ctx.channel.send(msg) def setup(bot: commands.Bot):