async def _evaluate_checks(self, command: commands.Command,
                               context: context_.Context) -> bool:
        checks = [*self._checks, *command.checks]
        if command.plugin is not None:
            checks.append(command.plugin.plugin_check)

        failed_checks = []
        for check in checks:
            try:
                if not await check(context):
                    failed_checks.append(
                        errors.CheckFailure(
                            f"Check {check.__name__} failed for command {command.name}"
                        ))
            except Exception as ex:
                error = errors.CheckFailure(str(ex))
                error.__cause__ = ex
                failed_checks.append(ex)

        if len(failed_checks) > 1:
            raise errors.CheckFailure("Multiple checks failed: " + ", ".join(
                str(ex) for ex in failed_checks))
        elif failed_checks:
            raise failed_checks[0]
        return True
Esempio n. 2
0
    async def is_runnable(self, context: context_.Context) -> bool:
        """
        Run all the checks for the command to determine whether or not it is
        runnable in the given context.

        Args:
            context (:obj:`~.context.Context`): The context to evaluate the checks with.

        Returns:
            :obj:`bool`: If the command is runnable in the context given.

        Raises:
            :obj:`~.errors.CheckFailure`: If the command is not runnable in the context given.
        """
        for check in self._checks:
            try:
                result = await check(context)
            except errors.MissingRequiredAttachment:
                # Bypass attachment check because we still want the command to show for the help
                # overview and it is unlikely that someone will call the help command with an attachment
                # to the message.
                result = True
            if result is False:
                raise errors.CheckFailure(f"Check {check.__name__} failed for command {self.name}")
        return True
Esempio n. 3
0
    async def is_runnable(self, context: context_.Context) -> bool:
        """
        Run all the checks for the command to determine whether or not it is
        runnable in the given context.

        Args:
            context (:obj:`~.context.Context`): The context to evaluate the checks with.

        Returns:
            :obj:`bool`: If the command is runnable in the context given.

        Raises:
            :obj:`~.errors.CheckFailure`: If the command is not runnable in the context given.
        """
        for check in self._checks:
            result = await check(context)
            if result is False:
                raise errors.CheckFailure(
                    f"Check {check.__name__} failed for command {self.name}")
        return True
Esempio n. 4
0
    async def is_runnable(self, context: context_.Context) -> bool:
        if getattr(self, "disabled", False):
            raise errors.CheckFailure("Command is disabled.")

        return await super().is_runnable(context)