diff --git a/bot.py b/bot.py index 512c147..44ddeb4 100644 --- a/bot.py +++ b/bot.py @@ -138,6 +138,22 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor await ctx.channel.send(embed=embed) +@bot.command(name='collect_messages', brief='Lists all messages with the given filters') +async def collect_messages_command(ctx: commands.Context, channel: Optional[discord.TextChannel] = None, + max_cnt: Optional[int] = 100, reaction_filter: Optional[str] = None): + typing = ctx.channel.trigger_typing() + if channel is None: + channel = ctx.channel + messages = async_filter(lambda m: _is_message_valid_for_selection(m, reaction_filter), channel.history(limit=max_cnt)) + messages = [item async for item in messages] + embed = discord.Embed( + title="List of matching messages", + description='\n'.join([m.content for m in messages]) + ) + await typing + await ctx.channel.send(embed=embed) + + def _is_message_valid_for_selection(message: discord.Message, reaction_filter: Optional[str] = None) -> bool: if message.clean_content.strip() == '': return False