From b8a2cf3f9194ec771c8bb688ec7334440ae5f266 Mon Sep 17 00:00:00 2001 From: PredaaA <46051820+PredaaA@users.noreply.github.com> Date: Thu, 22 Oct 2020 10:58:18 +0200 Subject: [PATCH] Move `bot_in_a_guild` from `redbot.core.checks` to `redbot.core.commands` (#4515) --- redbot/core/checks.py | 13 ++----------- redbot/core/commands/__init__.py | 1 + redbot/core/commands/requires.py | 29 ++++++++++++++++++++--------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/redbot/core/checks.py b/redbot/core/checks.py index cdc409a89..67ad77f96 100644 --- a/redbot/core/checks.py +++ b/redbot/core/checks.py @@ -5,6 +5,7 @@ import discord from .commands import ( bot_has_permissions, + bot_in_a_guild, has_permissions, is_owner, guildowner, @@ -13,7 +14,6 @@ from .commands import ( admin_or_permissions, mod, mod_or_permissions, - check as _check_decorator, ) from .utils.mod import ( is_mod_or_superior as _is_mod_or_superior, @@ -27,6 +27,7 @@ if TYPE_CHECKING: __all__ = [ "bot_has_permissions", + "bot_in_a_guild", "has_permissions", "is_owner", "guildowner", @@ -37,20 +38,10 @@ __all__ = [ "mod_or_permissions", "is_mod_or_superior", "is_admin_or_superior", - "bot_in_a_guild", "check_permissions", ] -def bot_in_a_guild(): - """Deny the command if the bot is not in a guild.""" - - async def predicate(ctx): - return len(ctx.bot.guilds) > 0 - - return _check_decorator(predicate) - - def is_mod_or_superior(ctx: "Context") -> Awaitable[bool]: warnings.warn( "`redbot.core.checks.is_mod_or_superior` is deprecated and will be removed in a future " diff --git a/redbot/core/commands/__init__.py b/redbot/core/commands/__init__.py index ab39b3065..e2f5cf452 100644 --- a/redbot/core/commands/__init__.py +++ b/redbot/core/commands/__init__.py @@ -52,6 +52,7 @@ from .requires import ( Requires as Requires, permissions_check as permissions_check, bot_has_permissions as bot_has_permissions, + bot_in_a_guild as bot_in_a_guild, has_permissions as has_permissions, has_guild_permissions as has_guild_permissions, is_owner as is_owner, diff --git a/redbot/core/commands/requires.py b/redbot/core/commands/requires.py index 3362885ce..645e074bb 100644 --- a/redbot/core/commands/requires.py +++ b/redbot/core/commands/requires.py @@ -11,22 +11,23 @@ import enum import inspect from collections import ChainMap from typing import ( - Union, - Optional, - List, - Callable, - Awaitable, - Dict, - Any, TYPE_CHECKING, - TypeVar, - Tuple, + Any, + Awaitable, + Callable, ClassVar, + Dict, + List, Mapping, + Optional, + Tuple, + TypeVar, + Union, ) import discord +from discord.ext.commands import check from .converter import GuildConverter from .errors import BotMissingPermissions @@ -47,6 +48,7 @@ __all__ = [ "Requires", "permissions_check", "bot_has_permissions", + "bot_in_a_guild", "has_permissions", "has_guild_permissions", "is_owner", @@ -705,6 +707,15 @@ def bot_has_permissions(**perms: bool): return decorator +def bot_in_a_guild(): + """Deny the command if the bot is not in a guild.""" + + async def predicate(ctx): + return len(ctx.bot.guilds) > 0 + + return check(predicate) + + def has_permissions(**perms: bool): """Restrict the command to users with these permissions.