public async Task Shop(int page = 1)
            {
                if (--page < 0)
                {
                    return;
                }

                var entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items)).ShopEntries);

                const int elementsPerPage = 9;
                await Context.Channel.SendPaginatedConfirmAsync(Context.Client as DiscordSocketClient, page, currentPage => {
                    var theseEntries = entries.Skip(currentPage *elementsPerPage).Take(elementsPerPage).ToArray();

                    if (!theseEntries.Any())
                    {
                        return(new EmbedBuilder().WithErrorColor()
                               .WithDescription(GetText("shop_none")));
                    }
                    var embed = new EmbedBuilder().WithOkColor()
                                .WithTitle(GetText("shop", _bc.BotConfig.CurrencySign));

                    for (var i = 0; i < theseEntries.Length; i++)
                    {
                        var entry = theseEntries[i];
                        embed.AddField(efb => efb.WithName($"#{currentPage * elementsPerPage + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
                    }
                    return(embed);
                }, (int)Math.Ceiling(entries.Count * 1d / elementsPerPage), reactUsers : new[] { Context.User as IGuildUser });
            }
예제 #2
0
            public async Task Shop(int page = 1)
            {
                if (--page < 0)
                {
                    return;
                }
                List <ShopEntry> entries;

                using (var uow = _db.UnitOfWork)
                {
                    entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
                                                                                     set => set.Include(x => x.ShopEntries)
                                                                                     .ThenInclude(x => x.Items)).ShopEntries);
                }

                await Context.SendPaginatedConfirmAsync(page, (curPage) =>
                {
                    var theseEntries = entries.Skip(curPage * 9).Take(9).ToArray();

                    if (!theseEntries.Any())
                    {
                        return(new EmbedBuilder().WithErrorColor()
                               .WithDescription(GetText("shop_none")));
                    }
                    var embed = new EmbedBuilder().WithOkColor()
                                .WithTitle(GetText("shop", _bc.BotConfig.CurrencySign));

                    for (int i = 0; i < theseEntries.Length; i++)
                    {
                        var entry = theseEntries[i];
                        embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
                    }
                    return(embed);
                }, entries.Count, 9, true);
            }
예제 #3
0
파일: FlowerShop.cs 프로젝트: KoshOTP/Taiga
            public async Task Shop(int page = 1)
            {
                if (page <= 0)
                {
                    return;
                }
                page -= 1;
                List <ShopEntry> entries;

                using (var uow = DbHandler.UnitOfWork())
                {
                    entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
                                                                                     set => set.Include(x => x.ShopEntries)
                                                                                     .ThenInclude(x => x.Items)).ShopEntries);
                }

                await Context.Channel.SendPaginatedConfirmAsync(page + 1, (curPage) =>
                {
                    var theseEntries = entries.Skip((curPage - 1) * 9).Take(9);

                    if (!theseEntries.Any())
                    {
                        return(new EmbedBuilder().WithErrorColor()
                               .WithDescription(GetText("shop_none")));
                    }
                    var embed = new EmbedBuilder().WithOkColor()
                                .WithTitle(GetText("shop", CurrencySign));

                    for (int i = 0; i < entries.Count; i++)
                    {
                        var entry = entries[i];
                        embed.AddField(efb => efb.WithName($"#{i + 1} - {entry.Price}{CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
                    }
                    return(embed);
                }, entries.Count / 9, true);
            }