Allow to exclude messages from random selection
This commit is contained in:
11
bot.py
11
bot.py
@@ -121,7 +121,7 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor
|
||||
typing = ctx.channel.trigger_typing()
|
||||
if channel is None:
|
||||
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]
|
||||
msg: discord.Message = random.choice(messages)
|
||||
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)
|
||||
|
||||
|
||||
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')
|
||||
async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = '', *, val: str = ''):
|
||||
if ctx.guild is None:
|
||||
|
||||
Reference in New Issue
Block a user