Allow to exclude messages from random selection

This commit is contained in:
2020-12-19 13:26:44 +01:00
parent 92f5d30250
commit f7e68ba8d6

11
bot.py
View File

@@ -121,7 +121,7 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor
typing = ctx.channel.trigger_typing() typing = ctx.channel.trigger_typing()
if channel is None: if channel is None:
channel = ctx.channel channel = ctx.channel
messages = async_filter(lambda m: m.clean_content.strip() != '', channel.history(limit=max_cnt)) messages = async_filter(_is_message_allowed_for_operations, channel.history(limit=max_cnt))
messages = [item async for item in messages] messages = [item async for item in messages]
msg: discord.Message = random.choice(messages) msg: discord.Message = random.choice(messages)
author: discord.abc.User = msg.author author: discord.abc.User = msg.author
@@ -134,6 +134,15 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor
await ctx.channel.send(embed=embed) await ctx.channel.send(embed=embed)
def _is_message_allowed_for_operations(message: discord.Message) -> bool:
if message.clean_content.strip() == '':
return False
for reaction in message.reactions:
if reaction.emoji == '':
return False
return True
@bot.command(name='config', brief='Change the configuration of this bot') @bot.command(name='config', brief='Change the configuration of this bot')
async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = '', *, val: str = ''): async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = '', *, val: str = ''):
if ctx.guild is None: if ctx.guild is None: