コード例 #1
0
    async def invoke(self, ctx):
        early_invoke = not self.invoke_without_command
        if early_invoke:
            await self.prepare(ctx)

        view = ctx.view
        previous = view.index
        view.skip_ws()
        trigger = view.get_word()

        if trigger:
            ctx.subcommand_passed = trigger
            ctx.invoked_subcommand = self.all_commands.get(trigger, None)

        if early_invoke:
            injected = hooked_wrapped_callback(self, ctx, self.callback)
            await injected(*ctx.args, **ctx.kwargs)

        if trigger and ctx.invoked_subcommand:
            ctx.invoked_with = trigger
            await ctx.invoked_subcommand.invoke(ctx)
        elif not early_invoke:
            view.index = previous
            view.previous = previous
            await super().invoke(ctx)
コード例 #2
0
    async def invoke(self, ctx):

        await self.prepare(ctx)

        # terminate the invoked_subcommand chain.
        # since we're in a regular command (and not a group) then
        # the invoked subcommand is None.
        ctx.invoked_subcommand = None
        injected = hooked_wrapped_callback(self, ctx, self.callback)

        # Checks if the user is already executing this command.
        # If that is true, we throw an exception
        if not ctx.bot.restricted.get(ctx.author.id):
            ctx.bot.restricted[ctx.author.id] = {}
        restrict = ctx.bot.restricted[ctx.author.id].get(self.name, None)
        if restrict:
            raise RestrictionError("Cannot use the command multiple times")
        else:
            ctx.bot.restricted[ctx.author.id][self.name] = True

        # Changes the channel to the DM channel

        dm_channel = ctx.author.dm_channel
        if not dm_channel:
            await ctx.author.create_dm()
        if ctx.channel != dm_channel:
            await ctx.channel.send(
                f"{ctx.author.mention}, I sent you a DM.\n*If you didn't receive it, correct your account settings*"
            )
        ctx.set_channel(ctx.author.dm_channel)
        await injected(*ctx.args, **ctx.kwargs)

        # Once the command has been terminated, we clear the restriction
        ctx.bot.restricted[ctx.author.id][self.name] = False
コード例 #3
0
async def invoke(self, ctx):
    await self.prepare(ctx)
    ctx.invoked_subcommand = None
    injected = hooked_wrapped_callback(self, ctx, self.callback)
    ret = await injected(*ctx.args, **ctx.kwargs)
    if ret is not None:
        await ctx.send(ret)
コード例 #4
0
    async def invoke(self, ctx):
        await self.prepare(ctx)

        # terminate the invoked_subcommand chain.
        # since we're in a regular command (and not a group) then
        # the invoked subcommand is None.
        ctx.invoked_subcommand = None
        injected = hooked_wrapped_callback(self, ctx, self.callback)

        #Does the DM channel stuff
        dm_channel = ctx.author.dm_channel
        if not dm_channel:
            await ctx.author.create_dm()
        if ctx.channel != dm_channel:
            await ctx.channel.send(
                f"{ctx.author.mention}, I sent you a DM.\n*If you didn't receive it, correct your account settings*"
            )
        ctx.set_channel(ctx.author.dm_channel)
        await injected(*ctx.args, **ctx.kwargs)
コード例 #5
0
    async def invoke(self, ctx):

        await self.prepare(ctx)

        # terminate the invoked_subcommand chain.
        # since we're in a regular command (and not a group) then
        # the invoked subcommand is None.
        ctx.invoked_subcommand = None
        injected = hooked_wrapped_callback(self, ctx, self.callback)

        # Checks if the user is already executing this command.
        # If that is true, we throw an exception
        if not ctx.bot.restricted.get(ctx.author.id):
            ctx.bot.restricted[ctx.author.id] = {}
        restrict = ctx.bot.restricted[ctx.author.id].get(self.name, None)
        if restrict:
            raise RestrictionError("Cannot use the command multiple times")
        else:
            ctx.bot.restricted[ctx.author.id][self.name] = True

        await injected(*ctx.args, **ctx.kwargs)

        # Once the command has been terminated, we clear the restriction
        ctx.bot.restricted[ctx.author.id][self.name] = False