[Warnings] Stop using inspect.getsource to check for is_owner check (#3516)

* Update helpers.py

* Create 3515.misc.rst

* Update helpers.py
This commit is contained in:
jack1142 2020-02-07 01:42:36 +01:00 committed by GitHub
parent 246f9ce17f
commit 8f7ba02ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -0,0 +1 @@
Don't use `inspect.getsource` to check for ``is_owner`` check.

View File

@ -1,9 +1,9 @@
from copy import copy from copy import copy
import asyncio import asyncio
import inspect
import discord import discord
from redbot.core import Config, checks, commands from redbot.core import Config, checks, commands
from redbot.core.commands.requires import PrivilegeLevel
from redbot.core.i18n import Translator from redbot.core.i18n import Translator
from redbot.core.utils.predicates import MessagePredicate from redbot.core.utils.predicates import MessagePredicate
@ -54,7 +54,9 @@ async def create_and_invoke_context(
try: try:
await realctx.bot.invoke(fctx) await realctx.bot.invoke(fctx)
except (commands.CheckFailure, commands.CommandOnCooldown): except (commands.CheckFailure, commands.CommandOnCooldown):
await fctx.reinvoke() # reinvoke bypasses checks and we don't want to run bot owner only commands here
if fctx.command.requires.privilege_level < PrivilegeLevel.BOT_OWNER:
await fctx.reinvoke()
def get_command_from_input(bot, userinput: str): def get_command_from_input(bot, userinput: str):
@ -69,9 +71,7 @@ def get_command_from_input(bot, userinput: str):
if com is None: if com is None:
return None, _("I could not find a command from that input!") return None, _("I could not find a command from that input!")
check_str = inspect.getsource(checks.is_owner) if com.requires.privilege_level >= PrivilegeLevel.BOT_OWNER:
if any(inspect.getsource(x) in check_str for x in com.checks):
# command the user specified has the is_owner check
return ( return (
None, None,
_("That command requires bot owner. I can't allow you to use that for an action"), _("That command requires bot owner. I can't allow you to use that for an action"),