Exemplo n.º 1
0
        public async Task helpAsync()
        {
            var modules = _commands.Modules;
            var pages   = new List <PageBuilder>();

            foreach (var module in modules)
            {
                var pageFields = new List <EmbedFieldBuilder>();

                foreach (CommandInfo command in module.Commands)
                {
                    EmbedFieldBuilder embedField = new EmbedFieldBuilder();
                    embedField.WithName(HelpUtilities.GetCommandUsage(command));
                    embedField.WithValue(command.Summary ?? "no information given");
                    pageFields.Add(embedField);
                }

                if (pageFields.Count <= 25)
                {
                    PageBuilder page = new PageBuilder();
                    page.WithTitle(module.Name);
                    page.WithFields(pageFields);
                    pages.Add(page);
                }
                else
                {
                    while (pageFields.Count > 0)
                    {
                        PageBuilder page = new PageBuilder();
                        page.WithTitle(module.Name);
                        page.WithFields(pageFields.Take(25));
                        pages.Add(page);
                        if (pageFields.Count > 25)
                        {
                            pageFields.RemoveRange(0, 24);
                        }
                        else
                        {
                            pageFields.Clear();
                        }
                    }
                }
            }
            var paginator = new StaticPaginatorBuilder()
                            .WithUsers(Context.User)
                            .WithPages(pages)
                            .WithFooter(PaginatorFooter.PageNumber | PaginatorFooter.Users)
                            .WithDefaultEmotes()
                            .Build();

            await _interactivity.SendPaginatorAsync(paginator, Context.Channel, TimeSpan.FromMinutes(2));
        }
Exemplo n.º 2
0
        public async Task CardAsync([Remainder] string name)
        {
            var result = await _cardService.Where(x => x.Name, name).AllAsync();

            var cards = result.Value.DistinctBy(x => x.Name).ToArray();
            var pages = cards.OrderBy(x => string.Compare(x.Name, name, StringComparison.OrdinalIgnoreCase)).Select((x, i) => MagicHelper.BuildPage(x, i, cards.Length));

            var paginator = new StaticPaginatorBuilder()
            {
                Pages = pages.ToList()
            }.WithTimoutedEmbed(null).Build();

            if (result.IsSuccess && result.Value.Count > 0)
            {
                await _interactivityService.SendPaginatorAsync(paginator, Context.Channel);
            }
        }
Exemplo n.º 3
0
        public async Task HelpAsync()
        {
            var commands = _commandService.Commands
                           .Where(x => x.Module.Attributes.All(z => z.GetType() != typeof(ExcludeFromHelpAttribute)))
                           .Where(x => x.Attributes.All(z => z.GetType() != typeof(ExcludeFromHelpAttribute)))
                           .DistinctBy(x => x.Aliases[0])
                           .GroupBy(x => x.Module)
                           .OrderBy(x => x.Key.Name)
                           .ToDictionary(x => x.Key);

            var pages = commands.Select(x => HelpPageBuilder
                                        .Build(x.Value.OrderBy(y => y.Name), x.Key));

            await _interactivityService.SendPaginatorAsync(
                new StaticPaginatorBuilder()
            {
                Pages = pages.ToList()
            }.Build(), Context.Channel);
        }
Exemplo n.º 4
0
        /// <summary>Returns an embed containing the player queue.
        /// </summary>
        public async Task QueueAsync(SocketCommandContext context)
        {
            var guild = context.Guild;

            //Checks if bot is connected to a voice channel
            if (!_lavaNode.HasPlayer(guild))
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateErrorEmbed("Could not acquire player."));

                return;
            }

            //Bot is connected to voice channel, so we get the player associated with the guild
            var player = _lavaNode.GetPlayer(guild);

            //If player isn't playing, then we return
            if (!(player.PlayerState is PlayerState.Playing))
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateErrorEmbed("I'm not playing anything right now."));

                return;
            }

            //If there are no more songs in queue except for the current playing song, we return with a reply
            //saying the currently playing song and that no more songs are queued
            if (player.Queue.Count < 1 && player.Track != null)
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateBasicEmbed("",
                                                                                              $"**Now playing: {player.Track.Title}**\nNo more songs queued.", Color.Blue));

                return;
            }

            try
            {
                //After checking if we have tracks in the queue

                //We save the count of tracks in queue to tracksCount variable
                var tracksCount = player.Queue.Count;

                /* We calculate the maximum items per page we want
                 * this will return the minimum number, either 10 or tracksCount*/
                var maxItemsPerPage = Math.Min(10, tracksCount);

                //We calculate how many pages we'll have (used to initialize array)
                var maxPages = tracksCount / maxItemsPerPage;

                //We initialize an array with size of maxPages
                var pages = new PageBuilder[maxPages];

                var trackNum = 2; //trackNum == 2 because we're not including the first track

                //We itterate through all the pages we need
                for (int i = 0; i < maxPages; i++)
                {
                    var descriptionBuilder = new StringBuilder();

                    //We take X items, equal to the number of maxItemsPerPage, so we don't overflow the embed max description length
                    var tracks = player.Queue.Skip(i).Take(maxItemsPerPage);

                    //We itterate through the tracks taken on the previous instruction
                    foreach (var track in tracks)
                    {
                        //We create the description for each page
                        descriptionBuilder.Append($"{trackNum}: [{track.Title}]({track.Url})\n");
                        trackNum++;
                    }

                    //We create the page, with the description created on the previous loop
                    pages[i] = new PageBuilder().WithTitle($"Now playing: {player.Track?.Title}")
                               .WithDescription($"{descriptionBuilder}").WithColor(Color.Blue);
                }

                //We create the paginator to send
                var paginator = new StaticPaginatorBuilder()
                                .WithUsers(context.User)
                                .WithFooter(PaginatorFooter.PageNumber)
                                .WithEmotes(new Dictionary <IEmote, PaginatorAction>()
                {
                    { new Emoji("⏮️"), PaginatorAction.SkipToStart },
                    { new Emoji("⬅️"), PaginatorAction.Backward },
                    { new Emoji("➡️"), PaginatorAction.Forward },
                    { new Emoji("⏭️"), PaginatorAction.SkipToEnd }
                })
                                .WithPages(pages)
                                .WithTimoutedEmbed(pages[0].Build().Embed.ToEmbedBuilder())
                                .Build();

                //Send the paginator to the text channel
                await _interactivityService.SendPaginatorAsync(paginator, context.Channel, TimeSpan.FromSeconds(150));
            }
            catch (Exception ex)
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateErrorEmbed(ex.Message));
            }
        }
Exemplo n.º 5
0
 public Task <InteractivityResult <object> > PagedReplyAsync(Interactivity.Pagination.PaginatorBuilder builder, TimeSpan?timeout = null)
 {
     return(InteractivityService.SendPaginatorAsync(builder.Build(),
                                                    Context.Channel, timeout: timeout));
 }