Ejemplo n.º 1
0
        public async Task BuyWaifu([Remainder] string str = "")
        {
            var shopwaifus = (await WaifuShopDb.GetAllShopWaifus(Context.Guild.Id)).DistinctBy(x => x.WaifuName);

            var waifu = await WaifuUtil.ProcessWaifuListAndRespond(await WaifuDb.SearchWaifus(str, false, shopwaifus.Select(x => x.Waifu)), this);

            if (waifu == null)
            {
                return;
            }
            var waifus = UserInventoryDb.GetWaifus(Context.User.Id, Context.Guild.Id);

            if (waifus.Any(x => x.Name.Equals(waifu.Name)))
            {
                await Context.Channel.SendMessageAsync("You already have **" + waifu.Name + "**.");

                return;
            }

            ShopWaifu shopWaifu = shopwaifus.FirstOrDefault(x => x.Waifu.Equals(waifu) && x.Limited != 0);

            if (shopWaifu == null)
            {
                await Context.Channel.SendMessageAsync($"**{waifu.Name}** is not currently for sale! Try the `waifushop` command.");

                return;
            }

            var price = WaifuUtil.GetPrice(waifu.Tier, shopWaifu.Discount);

            try
            {
                await BalanceDb.AddToasties(Context.User.Id, -price, Context.Guild.Id);
            }
            catch (Exception ex)
            {
                await Context.Channel.SendMessageAsync(ex.Message);

                return;
            }

            await UserInventoryDb.AddWaifu(Context.User.Id, waifu, Context.Guild.Id);

            await Context.Channel.SendMessageAsync($"Congratulations! You bought **{waifu.Name}**!", false, WaifuUtil.WaifuEmbedBuilder(waifu).Build());

            await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, price / 13, Context.Guild.Id);

            if (shopWaifu.Limited > 0)
            {
                shopWaifu.BoughtBy = Context.User.Id;
                shopWaifu.Limited -= 1;
                await WaifuShopDb.UpdateItem(shopWaifu);
            }
        }
Ejemplo n.º 2
0
        public static async Task <EmbedBuilder> ServerInfo(SocketGuild guild)
        {
            var eb = new EmbedBuilder();

            string name = guild.Name;

            if (PremiumDb.IsPremium(guild.Id, ProType.GuildPlus))
            {
                name += " | T1 Guild 🌟";
            }
            else if (PremiumDb.IsPremium(guild.Id, ProType.Guild))
            {
                name += " | T2 Guild ⭐";
            }
            eb.WithAuthor(name, guild.IconUrl, LinkHelper.GetRedirectUrl(LinkHelper.Patreon, "Patreon", "cmd-embed-info"));

            var toasties = (await BalanceDb.GetAllToastiesRaw(guild.Id)).OrderByDescending(x => x.Amount).ToList();
            var waifus   = await UserInventoryDb.GetAllWaifuItems(guild.Id);

            string field = "";

            field += $"Total toasties: **{toasties.Sum(x => (long)x.Amount).ToString("n0")}**\n";
            SocketGuildUser user = null;
            int             i    = 0;

            while (i < toasties.Count && (user == null || user.IsBot))
            {
                user = guild.GetUser(toasties[i++].UserId);
            }
            if (user != null)
            {
                field += $"Richest user: {user.Mention} - **{toasties.FirstOrDefault(x => x.UserId == user.Id).Amount.ToString("n0")}**\n";
            }

            var bank = toasties.FirstOrDefault(x => x.UserId == Program.GetClient().CurrentUser.Id);

            field += $"Bank balance: **{(bank == null ? "0" : bank.Amount.ToString("n0"))}**\n";
            eb.AddField("Toasties <:toastie3:454441133876183060>", field);

            field  = "";
            field += $"Total waifus: **{waifus.Count.ToString("n0")}**\n";
            field += $"Total waifu value: **{waifus.Sum(x => Convert.ToInt64(WaifuUtil.GetPrice(x.Waifu.Tier, 0))).ToString("n0")}**\n";
            var groupedwaifus = waifus.GroupBy(x => x.UserId).OrderByDescending(x => x.Count()).ToList();
            IGrouping <ulong, UserInventory> most = null;

            user = null;
            i    = 0;
            while (i < groupedwaifus.Count && (user == null || user.IsBot))
            {
                most = groupedwaifus[i];
                user = guild.GetUser(groupedwaifus[i++].Key);
            }
            if (most != null && user != null)
            {
                field += $"Most waifus: {user.Mention} - **{most.Count().ToString("n0")}**\n";
            }

            groupedwaifus = groupedwaifus.OrderByDescending(x => x.Sum(y => WaifuUtil.GetPrice(y.Waifu.Tier, 0))).ToList();
            most          = null;
            user          = null;
            i             = 0;
            while (i < groupedwaifus.Count && (user == null || user.IsBot))
            {
                most = groupedwaifus[i];
                user = guild.GetUser(groupedwaifus[i++].Key);
            }
            if (most != null && user != null)
            {
                field += $"Highest value: {user.Mention} - **{most.Sum(y => WaifuUtil.GetPrice(y.Waifu.Tier, 0)).ToString("n0")}**\n";
            }
            eb.AddField("Waifus :two_hearts:", field);

            eb.WithColor(BasicUtil.RandomColor());
            eb.WithFooter("To be expanded");
            eb.WithThumbnailUrl(guild.IconUrl);
            return(eb);
        }