def check_aliases(parent, child_name, aliases): # child_name is the name of the child to be updated, which will be ignored if parent.case_insensitive: aliases = [alias.lower() for alias in aliases] aliases_set = set() for alias in aliases: cmd = parent.get_command(alias) if cmd is not None and (cmd.name != child_name or cmd.name == alias): raise commands.CommandRegistrationError(alias, alias_conflict=True) if alias in aliases_set: raise commands.CommandRegistrationError(alias, alias_conflict=True) else: aliases_set.add(alias)
def add_command(self, command): """Adds a command to the internal list. If the command passed has attribute ``emojis``, will be treated as an instance of :class:`.ReactionCommand`. Adds :attr:`.ReactionCommand.emojis` to the internal mapping of reaction commands. Parameters ---------- command: :class:`commands.Command <discord.ext.commands.Command>` The command to add """ try: if any(emoji in self.emoji_mapping for emoji in command.emojis): raise commands.CommandRegistrationError(' '.join( command.emojis)) try: super().add_command(command) except Exception as e: raise e else: for emoji in command.emojis: self.emoji_mapping[emoji] = command except AttributeError as e: super().add_command(command)
def _add_root_aliases(self, command: commands.Command) -> None: """Recursively add root aliases for `command` and any of its subcommands.""" if isinstance(command, commands.Group): for subcommand in command.commands: self._add_root_aliases(subcommand) for alias in getattr(command, "root_aliases", ()): if alias in self.all_commands: raise commands.CommandRegistrationError(alias, alias_conflict=True) self.all_commands[alias] = command
def decorator(func): if isinstance(func, ApplicationCommand): if not func.guild_id: raise commands.CommandRegistrationError( 'Only guild commands can have permissions') func.permissions.append(Permissions(user_id, allow, 2)) else: if not hasattr(func, '__permissions__'): func.__permissions__ = list() func.__permissions__.append(Permissions(user_id, allow, 2)) return func
def callback(self, function): self._callback = function self.module = function.__module__ signature = inspect.signature(function) params = signature.parameters.copy() self.params = {} for key, value in list(params.items())[1:]: param = value.annotation if param is value.empty: # if type not passed type is str param = str if isinstance(param, str): param = eval(param, function.__globals__) if hasattr(param, '__origin__') and param.__origin__ is typing.Union \ and len(param.__args__) == 2 and isinstance(None, param.__args__[-1]): # escape typing.Optional optional = True param = param.__args__[0] elif value.default is not value.empty: # make arg optional if it has default value optional = True else: optional = False if not isinstance(param, type(slash_args.Arg)): param = slash_args.Arg[param] if param.type is None: param = param[str] if isinstance(param, type(slash_args.Choice)): param.check_types() if param.name: key = param.name else: param.name = key if param.doc is None: param.doc = key param.optional = optional self.params[key] = param if hasattr(function, '__permissions__') and not self.guild_id: raise commands.CommandRegistrationError( 'Only guild commands can have permissions') self.permissions = function.__permissions__ if hasattr( function, '__permissions__') else list()