"""The MIT License (MIT)Copyright (c) 2015-2021 RapptzCopyright (c) 2021-present Pycord DevelopmentPermission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationthe rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHERDEALINGS IN THE SOFTWARE."""from__future__importannotationsfromtypingimportTYPE_CHECKING,Any,Callable,Generator,TypeVarimportdiscordfrom...cogimportCogfrom...commandsimportApplicationCommand,SlashCommandGroupifTYPE_CHECKING:from.coreimportCommand__all__=("Cog",)CogT=TypeVar("CogT",bound="Cog")FuncT=TypeVar("FuncT",bound=Callable[...,Any])MISSING:Any=discord.utils.MISSING
[docs]classCog(Cog):def__new__(cls:type[CogT],*args:Any,**kwargs:Any)->CogT:# For issue 426, we need to store a copy of the command objects# since we modify them to inject `self` to them.# To do this, we need to interfere with the Cog creation process.returnsuper().__new__(cls)
[docs]defwalk_commands(self)->Generator[Command]:"""An iterator that recursively walks through this cog's commands and subcommands. Yields ------ Union[:class:`.Command`, :class:`.Group`] A command or group from the cog. """from.coreimportGroupMixinforcommandinself.__cog_commands__:ifnotisinstance(command,ApplicationCommand):ifcommand.parentisNone:yieldcommandifisinstance(command,GroupMixin):yield fromcommand.walk_commands()elifisinstance(command,SlashCommandGroup):yield fromcommand.walk_commands()else:yieldcommand
[docs]defget_commands(self)->list[ApplicationCommand|Command]:r""" Returns -------- List[Union[:class:`~discord.ApplicationCommand`, :class:`.Command`]] A :class:`list` of commands that are defined inside this cog. .. note:: This does not include subcommands. """return[cforcinself.__cog_commands__ifc.parentisNone]