コード例 #1
0
        /// <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!
        }
コード例 #2
0
        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."));
        }
コード例 #3
0
        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}."));
        }
コード例 #4
0
        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."));
        }
コード例 #5
0
        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."));
        }
コード例 #6
0
        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."));
        }
コード例 #7
0
 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.");
     }
 }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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.");
            }
        }
コード例 #13
0
 public DiscordResponseCommandResult(DiscordCommandContext context, LocalMessage message)
     : base(context)
 {
     Message = message;
 }
コード例 #14
0
 protected DiscordCommandResult(DiscordCommandContext context)
 {
     Context = context;
 }
コード例 #15
0
 public DiscordMenuCommandResult(DiscordCommandContext context, MenuBase menu)
     : base(context)
 {
     _menu = menu;
 }
コード例 #16
0
 public abstract ValueTask <CheckResult> CheckAsync(DiscordCommandContext context);
コード例 #17
0
 public DiscordReactionCommandResult(DiscordCommandContext context, IEmoji emoji)
     : base(context)
 {
     Emoji = emoji;
 }
コード例 #18
0
 public DiscordMenuCommandResult(DiscordCommandContext context, MenuBase menu, TimeSpan timeout)
     : base(context)
 {
     Menu    = menu;
     Timeout = timeout;
 }
コード例 #19
0
ファイル: DiscordBotBase.cs プロジェクト: phosphene47/Disqord
 protected virtual ValueTask AfterExecutedAsync(IResult result, DiscordCommandContext context)
 => default;
コード例 #20
0
ファイル: DiscordBotBase.cs プロジェクト: phosphene47/Disqord
 protected virtual ValueTask <bool> BeforeExecutedAsync(DiscordCommandContext context)
 => new ValueTask <bool>(true);
コード例 #21
0
 public Token(DiscordCommandContext context, CommandQueueDelegate func)
 {
     Context = context;
     _func   = func;
 }
コード例 #22
0
 public abstract ValueTask <CheckResult> CheckAsync(object argument, DiscordCommandContext context);
コード例 #23
0
        /// <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));
        }
コード例 #24
0
 /// <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);
コード例 #25
0
 public Token(string input, DiscordCommandContext context, CommandQueueDelegate func)
 {
     _input  = input;
     Context = context;
     _func   = func;
 }