Esempio n. 1
0
        /// <summary>
        ///     Post-command execution handling.
        /// </summary>
        private async Task OnCommandExecutedAsync(Optional <CommandInfo> commandInfo, ICommandContext context, IResult result)
        {
            // Bails if the generic result doesn't have an error reason, or if it's an unknown command error.
            if (string.IsNullOrEmpty(result.ErrorReason) || result.Error == CommandError.UnknownCommand)
            {
                return;
            }
            var embed = new EmbedBuilder();

            switch (result)
            {
            case CommandRuntimeResult customResult:
                switch (customResult.Type)
                {
                case ResultType.Unknown:
                    break;

                case ResultType.Info:
                    embed = EmbedHelper.FromInfo(description: customResult.Reason);
                    break;

                case ResultType.Warning:
                    embed = EmbedHelper.FromWarning(description: customResult.Reason);
                    break;

                case ResultType.Error:
                    embed = EmbedHelper.FromError(description: customResult.Reason);
                    break;

                case ResultType.Success:
                    embed = EmbedHelper.FromSuccess(description: customResult.Reason);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            default:
                embed = EmbedHelper.FromError(description: result.ErrorReason);
                break;
            }
            await context.Channel.SendMessageAsync("", embed : embed.Build()).ConfigureAwait(false);

            if (commandInfo.IsSpecified)
            {
                _loggingService.Log(
                    $"{context.User} executed \"{commandInfo.Value.Aliases.FirstOrDefault()}\" in {context.Message.GetPostedAt()}." +
                    Environment.NewLine +
                    $"Result: {result.ErrorReason}" +
                    Environment.NewLine +
                    $"Result Type: {result.GetType().Name}",
                    LogSeverity.Verbose);
            }
        }
Esempio n. 2
0
        private async Task HandlePostCommandExecutionAsync(Optional <CommandInfo> commandInfo, ICommandContext context,
                                                           IResult result)
        {
            if (result.Error == CommandError.UnknownCommand)
            {
                return;
            }
            if (!string.IsNullOrEmpty(result.ErrorReason))
            {
                Embed embed;
                switch (result)
                {
                case CommonResult commonResult:
                    switch (commonResult.CommonResultType)
                    {
                    default:
                        embed = EmbedHelper.FromInfo(description: commonResult.Reason);
                        break;

                    case CommonResultType.Warning:
                        embed = EmbedHelper.FromWarning(description: commonResult.Reason);
                        break;

                    case CommonResultType.Error:
                        embed = EmbedHelper.FromError(description: commonResult.Reason);
                        break;

                    case CommonResultType.Success:
                        embed = EmbedHelper.FromSuccess(description: commonResult.Reason);
                        break;
                    }

                    break;

                default:
                    embed = EmbedHelper.FromError(description: result.ErrorReason);
                    break;
                }

                var message = await context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                if (result.Error.HasValue)
                {
                    _ = Task.Delay(TimeSpan.FromSeconds(5))
                        .ContinueWith(_ => message?.DeleteAsync().ConfigureAwait(false));
                }
            }
        }