Skip to content

Gave BeforeExecutionAsync() a bool return type that decides whether or not to continue with Task execution.

Mateusz Brawański requested to merge github/fork/AyBee0/master into master

Created by: AyBee0

Summary

Implements an ability for the developer to decide whether or not to let the library handle the command execution.

Details

The virtual method BeforeExecutionAsync now has a return type of bool, which would be used to decide whether or not to continue with the command execution:

public virtual Task<bool> BeforeExecutionAsync(CommandContext ctx)
            => Task.FromResult(true);

The result is then handled in Command.cs:

var shouldHandleExecution = await bcmBefore.BeforeExecutionAsync(ctx).ConfigureAwait(false);
if (!shouldHandleExecution)
{
    executed = true;
    break;
}

A good use case would be the following example, where the bot first determines whether or not the user is allowed to use commands in the current channel:

public override Task<bool> BeforeExecutionAsync(CommandContext ctx)
{
    return MyDAL.Guilds[ctx.Guild].UserCanUseBotInChannel(ctx);
}

Changes proposed

  • Give BeforeExecutionAsync a return type that would decide if the library would handle the command.

Notes

I wasn't sure whether or not I should set executed = true when false is returned, but I assumed so since not setting it would cause it to be handled as if no overload was found.

Merge request reports

Loading