/// <inheritdoc/> public void Post(DiscordCommandContext context, CommandQueueDelegate func) { if (context == null) { throw new ArgumentNullException(nameof(context)); } Bucket kamaji; if (context.GuildId == null) { lock (this) { kamaji = _privateBucket ??= new Bucket(Logger, DegreeOfParallelism); } } else { kamaji = _guildBuckets.GetOrAdd(context.GuildId.Value, (_, queue) => new Bucket(queue.Logger, queue.DegreeOfParallelism), this); } var bathToken = new Token(context, func); kamaji.Post(bathToken); // Thank you, mr boiler man! }
public override ValueTask <CheckResult> CheckAsync(object argument, DiscordCommandContext context) { if (argument is IUser user && user.Id != context.Author.Id) { return(Success()); } return(Failure("The provided argument must be another user.")); }
public override ValueTask <CheckResult> CheckAsync(DiscordCommandContext context) { if (context.ChannelId == Id) { return(Success()); } return(Failure($"This can only be executed in the channel with the ID {Id}.")); }
public override ValueTask <CheckResult> CheckAsync(object argument, DiscordCommandContext context) { if (argument is IUser user && !user.IsBot) { return(Success()); } return(Failure("The provided argument must not be a bot user.")); }
public override sealed ValueTask <CheckResult> CheckAsync(DiscordCommandContext context) { if (context.GuildId == null) { return(Success()); } return(Failure("This can only be executed outside of a guild.")); }
public override async ValueTask <CheckResult> CheckAsync(DiscordCommandContext context) { if (await context.Bot.IsOwnerAsync(context.Author.Id).ConfigureAwait(false)) { return(Success()); } return(Failure("This can only be executed by the bot owners.")); }
private async ValueTask DisposeContextAsync(DiscordCommandContext context) { try { await context.DisposeAsync().ConfigureAwait(false); } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while disposing of the command context."); } }
private async ValueTask <bool> InvokeAfterExecutedAsync(DiscordCommandContext context, IResult result) { try { return(await AfterExecutedAsync(context, result).ConfigureAwait(false)); } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while executing the after executed callback."); return(true); } }
public override sealed ValueTask <CheckResult> CheckAsync(DiscordCommandContext context) { if (context.GuildId == null) { return(Failure("This can only be executed within a guild.")); } if (context is not DiscordGuildCommandContext discordContext) { throw new InvalidOperationException($"The {GetType().Name} only accepts a DiscordGuildCommandContext."); } return(CheckAsync(discordContext)); }
private async ValueTask InternalHandleCommandExecutedAsync(DiscordCommandContext context, DiscordCommandResult result) { try { await using (RuntimeDisposal.WrapAsync(result)) { await result.ExecuteAsync().ConfigureAwait(false); } } catch (Exception ex) { Logger.LogError(ex, "An exception occurred when handling command result of type {0}.", result.GetType().Name); } await DisposeContextAsync(context).ConfigureAwait(false); }
private async ValueTask InternalHandleFailedResultAsync(DiscordCommandContext context, FailedResult result) { try { await HandleFailedResultAsync(context, result).ConfigureAwait(false); } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while handling the failed result of type {0}.", result.GetType().Name); } if (result is CommandNotFoundResult && _masterService != null) { await _masterService.HandleCommandNotFound(context).ConfigureAwait(false); } await DisposeContextAsync(context).ConfigureAwait(false); }
public async Task ExecuteAsync(DiscordCommandContext context) { try { var result = await Commands.ExecuteAsync(context.Input, context).ConfigureAwait(false); if (result is not FailedResult failedResult) { return; } // These will be handled by the CommandExecutionFailed event handler. if (result is CommandExecutionFailedResult) { return; } _ = InternalHandleFailedResultAsync(context, failedResult); } catch (Exception ex) { Logger.LogError(ex, "An exception occurred while attempting to execute commands."); } }
public DiscordResponseCommandResult(DiscordCommandContext context, LocalMessage message) : base(context) { Message = message; }
protected DiscordCommandResult(DiscordCommandContext context) { Context = context; }
public DiscordMenuCommandResult(DiscordCommandContext context, MenuBase menu) : base(context) { _menu = menu; }
public abstract ValueTask <CheckResult> CheckAsync(DiscordCommandContext context);
public DiscordReactionCommandResult(DiscordCommandContext context, IEmoji emoji) : base(context) { Emoji = emoji; }
public DiscordMenuCommandResult(DiscordCommandContext context, MenuBase menu, TimeSpan timeout) : base(context) { Menu = menu; Timeout = timeout; }
protected virtual ValueTask AfterExecutedAsync(IResult result, DiscordCommandContext context) => default;
protected virtual ValueTask <bool> BeforeExecutedAsync(DiscordCommandContext context) => new ValueTask <bool>(true);
public Token(DiscordCommandContext context, CommandQueueDelegate func) { Context = context; _func = func; }
public abstract ValueTask <CheckResult> CheckAsync(object argument, DiscordCommandContext context);
/// <inheritdoc/> public override sealed ValueTask <TypeParserResult <T> > ParseAsync(Parameter parameter, string value, DiscordCommandContext context) { if (context.GuildId == null) { return(Failure("This can only be executed within a guild.")); } if (context is not DiscordGuildCommandContext discordContext) { throw new InvalidOperationException($"The {GetType().Name} only accepts a DiscordGuildCommandContext."); } return(ParseAsync(parameter, value, discordContext)); }
/// <summary> /// Attempts to parse the provided raw argument to the <typeparamref name="T"/> type. /// </summary> /// <param name="parameter"> The currently parsed <see cref="Parameter"/>. </param> /// <param name="value"> The raw argument to parse. </param> /// <param name="context"> The context used for execution. </param> /// <returns> /// A <see cref="ValueTask{TResult}"/> representing the parsing work /// that wraps the parsing result. /// </returns> public abstract ValueTask <TypeParserResult <T> > ParseAsync(Parameter parameter, string value, DiscordCommandContext context);
public Token(string input, DiscordCommandContext context, CommandQueueDelegate func) { _input = input; Context = context; _func = func; }