[Core] Add Red.message_eligible_as_command (#4077)

* [Core] Add `Red.message_eligible_as_command`

  - This is a small utility function which makes it easy for cog
  creators to treat non-command messages as commands correctly.

  - This also modifies `Red.ignored_channel_or_guild`'s signature to
  explicitly add support for passing a message object (the only needed
  attributes are entirely shared with context)

* Update redbot/core/bot.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* address review

* Rename

* remove webhhok check, the issue wasn't possible under normal operation

* Ah yes, ctx.bot in a method of the bot...

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Michael H
2020-07-18 09:38:57 -04:00
committed by GitHub
parent c9ce4a78e6
commit 1852420b98
2 changed files with 52 additions and 29 deletions

View File

@@ -4,25 +4,5 @@ from . import commands
def init_global_checks(bot):
@bot.check_once
def minimum_bot_perms(ctx) -> bool:
"""
Too many 403, 401, and 429 Errors can cause bots to get global'd
It's reasonable to assume the below as a minimum amount of perms for
commands.
"""
return ctx.channel.permissions_for(ctx.me).send_messages
@bot.check_once
async def whiteblacklist_checks(ctx) -> bool:
return await ctx.bot.allowed_by_whitelist_blacklist(ctx.author)
@bot.check_once
async def ignore_checks(ctx) -> bool:
"""Check the channel or server is not ignored"""
return await ctx.bot.ignored_channel_or_guild(ctx)
@bot.check_once
def bots(ctx) -> bool:
"""Check the user is not another bot."""
return not ctx.author.bot
async def check_message_is_eligible_as_command(ctx: commands.Context) -> bool:
return await ctx.bot.message_eligible_as_command(ctx.message)