예제 #1
0
        public async Task HelpAsync([Summary("The command to get information about."), Remainder] string command = null)
        {
            if (command == null) //run cmds command
            {
                await _commands.Commands.Where(x => x.Name == "commands").First().ExecuteAsync(Context, ParseResult.FromSuccess(new List <TypeReaderValue> {
                    new TypeReaderValue(null, 1f)
                }, new List <TypeReaderValue>()), _services);

                return;
            }

            var cmds = _commands.Commands.Where(x => ((string.IsNullOrEmpty(x.Module.Group) ? "" : $"{x.Module.Group} ") + x.Name).TrimEnd(' ') == command);

            if (cmds.Any())
            {
                var msg = await _inter.SendPaginatorAsync(_misc.GenerateCommandInfo(cmds, Context.User as SocketGuildUser).Build(), Context.Channel);

                if (msg.IsCanceled)
                {
                    await msg.Message.DeleteAsync();
                }
            }
            else
            {
                var split = command.Split(' ');

                var aliases = _commands.Commands.Where(x => ((x.Module.Group == null && split.Length < 2) ||
                                                             x.Module.Group == split[0]) &&
                                                       x.Aliases.Any(y => y == command || (split.Length > 1 && y == split[1]
                                                                                           )));

                if (aliases.Any())
                {
                    var msg = await _inter.SendPaginatorAsync(_misc.GenerateCommandInfo(aliases, Context.User as SocketGuildUser).Build(), Context.Channel);

                    if (msg.IsCanceled)
                    {
                        await msg.Message.DeleteAsync();
                    }
                }
                else
                {
                    await ReplyAsync("This command does not exist.");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sends a deferred paginated message.
        /// </summary>
        /// <param name="embeds">The embed pages.</param>
        protected async Task SendDeferredPaginatedEmbedAsync(Embed[] embeds)
        {
            List <PageBuilder> pages = new();

            foreach (Embed embed in embeds)
            {
                PageBuilder pageBuilder = new PageBuilder().WithTitle(embed.Title)
                                          .WithDescription(embed.Description);
                foreach (EmbedField field in embed.Fields)
                {
                    pageBuilder.AddField(new EmbedFieldBuilder()
                    {
                        Name     = field.Name,
                        Value    = field.Value,
                        IsInline = field.Inline,
                    });
                }
                if (embed.Color.HasValue)
                {
                    pageBuilder.WithColor(embed.Color.Value);
                }
                if (embed.Thumbnail.HasValue)
                {
                    pageBuilder.WithThumbnailUrl(embed.Thumbnail.Value.Url);
                }
                if (embed.Footer.HasValue)
                {
                    pageBuilder.WithFooter(new EmbedFooterBuilder()
                    {
                        Text    = embed.Footer.Value.Text,
                        IconUrl = embed.Footer.HasValue ? embed.Footer.Value.IconUrl : null,
                    });
                }
                pages.Add(pageBuilder);
            }

            int             paginatorTimeout = Convert.ToInt32(Configuration["paginatorTimeout"]);
            StaticPaginator paginator        = new StaticPaginatorBuilder()
                                               .WithPages(pages)
                                               .WithDefaultButtons(Configuration)
                                               .WithJumpInputPrompt("Navegación de páginas")
                                               .WithJumpInputTextLabel($"Navegar a la página (1-{pages.Count}):")
                                               .WithExpiredJumpInputMessage("La interacción expiró. Por favor, ejecutá el comando nuevamente para volver a interactuar.")
                                               .WithInvalidJumpInputMessage($"La página a ingresar debe ser un número entre {Format.Bold("1")} y {Format.Bold(pages.Count.ToString())}.")
                                               .WithJumpInputInUseMessage("La función para saltar de página se encuentra actualmente en uso por otro usuario")
                                               .Build();
            await InteractiveService.SendPaginatorAsync(paginator, Context.Interaction as SocketInteraction, responseType : InteractionResponseType.DeferredChannelMessageWithSource, resetTimeoutOnInput : true, timeout : TimeSpan.FromSeconds(paginatorTimeout));
        }