mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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:
parent
246f9ce17f
commit
8f7ba02ab1
1
changelog.d/warnings/3515.misc.rst
Normal file
1
changelog.d/warnings/3515.misc.rst
Normal file
@ -0,0 +1 @@
|
||||
Don't use `inspect.getsource` to check for ``is_owner`` check.
|
||||
@ -1,9 +1,9 @@
|
||||
from copy import copy
|
||||
import asyncio
|
||||
import inspect
|
||||
import discord
|
||||
|
||||
from redbot.core import Config, checks, commands
|
||||
from redbot.core.commands.requires import PrivilegeLevel
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils.predicates import MessagePredicate
|
||||
|
||||
@ -54,7 +54,9 @@ async def create_and_invoke_context(
|
||||
try:
|
||||
await realctx.bot.invoke(fctx)
|
||||
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):
|
||||
@ -69,9 +71,7 @@ def get_command_from_input(bot, userinput: str):
|
||||
if com is None:
|
||||
return None, _("I could not find a command from that input!")
|
||||
|
||||
check_str = inspect.getsource(checks.is_owner)
|
||||
if any(inspect.getsource(x) in check_str for x in com.checks):
|
||||
# command the user specified has the is_owner check
|
||||
if com.requires.privilege_level >= PrivilegeLevel.BOT_OWNER:
|
||||
return (
|
||||
None,
|
||||
_("That command requires bot owner. I can't allow you to use that for an action"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user