Ejemplo n.º 1
0
        private async Task <PaginatedEmbed> CreatePaginatedEmbedAsync(List <Reminder> reminders, bool full = false)
        {
            var embed = new PaginatedEmbed()
            {
                Pages       = new List <PaginatedEmbedPage>(),
                ResponseFor = Context.User,
                Title       = full ? "Upozornění" : "Moje upozornění"
            };

            var chunks = reminders.SplitInParts(EmbedBuilder.MaxFieldCount);

            foreach (var chunk in chunks)
            {
                var page = new PaginatedEmbedPage(null);

                foreach (var reminder in chunk)
                {
                    var title = await CreateFieldTitleAsync(reminder, full);

                    if (string.IsNullOrEmpty(title))
                    {
                        continue;
                    }

                    page.AddField(title, $"ID: {reminder.RemindID}\nZpráva: {reminder.Message}\nZa: {(reminder.At - DateTime.Now).ToFullCzechTimeString()}");
                }

                if (page.AnyField())
                {
                    embed.Pages.Add(page);
                }
            }

            return(embed);
        }
Ejemplo n.º 2
0
        public async Task GetModulesAsync()
        {
            var moduleIdAttribute = typeof(ModuleIDAttribute);
            var unloadedModules   = GetUnloadedModules();
            var modulesChunk      = CommandService.Modules
                                    .SplitInParts(EmbedBuilder.MaxFieldCount);

            var pages = new List <PaginatedEmbedPage>();

            foreach (var chunk in modulesChunk)
            {
                var page = new PaginatedEmbedPage(null);

                foreach (var item in chunk)
                {
                    var attribute = item.Attributes.FirstOrDefault(o => o.GetType() == moduleIdAttribute) as ModuleIDAttribute;

                    var info = item.Name + (string.IsNullOrEmpty(item.Group) ? "" : $" ({item.Group})");
                    page.AddField(attribute.ID, info + (unloadedModules.Contains(attribute.ID) ? " - **Deaktivován**" : ""), false);
                }

                if (page.AnyField())
                {
                    pages.Add(page);
                }
            }

            if (pages.Count == 0)
            {
                await ReplyAsync("Nebyl nalezen žádný modul.");

                return;
            }

            var embed = new PaginatedEmbed()
            {
                Title       = "Seznam modulů",
                Pages       = pages,
                ResponseFor = Context.User,
                Thumbnail   = Context.Client.CurrentUser.GetUserAvatarUrl()
            };

            await SendPaginatedEmbedAsync(embed);
        }
Ejemplo n.º 3
0
        public async Task ListMethodsAsync()
        {
            var embed = new PaginatedEmbed()
            {
                Pages       = new List <PaginatedEmbedPage>(),
                ResponseFor = Context.User,
                Thumbnail   = Context.Client.CurrentUser.GetUserAvatarUrl(),
                Title       = "Konfigurace metod"
            };

            using var service = GetService <IGrillBotRepository>();
            var methods = await service.Service.ConfigRepository.GetAllMethods(Context.Guild.Id, true).ToListAsync();

            foreach (var group in methods.GroupBy(o => o.Group))
            {
                var page = new PaginatedEmbedPage(null);

                foreach (var method in group)
                {
                    var value = string.Join("\n", new[]
                    {
                        $"ID: **{method.ID}**",
                        $"Počet oprávnění: **{method.Permissions.Count.FormatWithSpaces()}**",
                        $"Počet použití: **{method.UsedCount.FormatWithSpaces()}**"
                    });

                    page.AddField($"{method.Group}/{method.Command}", value);
                }

                if (page.AnyField())
                {
                    embed.Pages.Add(page);
                }
            }

            await SendPaginatedEmbedAsync(embed);
        }