예제 #1
0
파일: Timers.cs 프로젝트: ta1H3n/Namiko
        public static async Task <int> SendRewards(IEnumerable <ulong> voters)
        {
            int sent = 0;

            foreach (var x in voters)
            {
                try
                {
                    var type = LootBoxType.Vote;
                    if (PremiumDb.IsPremium(x, ProType.ProPlus))
                    {
                        type = LootBoxType.Premium;
                    }

                    await LootBoxDb.AddLootbox(x, type, 1);

                    sent++;
                    var user = Program.GetClient().GetUser(x);
                    var ch   = await user.CreateDMChannelAsync();

                    await ch.SendMessageAsync(embed : new EmbedBuilderPrepared(user)
                                              .WithDescription($"Thank you for voting for me! I have given you a **{type.ToString()} Lootbox**! :star:\n" +
                                                               $"You can open it in a server of your choice by typing `!open`")
                                              .Build());
                }
                catch { }
            }
            return(sent);
        }
예제 #2
0
        public async Task Weekly()
        {
            var weekly = WeeklyDb.GetWeekly(Context.User.Id, Context.Guild.Id);

            if (weekly == null)
            {
                weekly = new Weekly
                {
                    GuildId = Context.Guild.Id,
                    UserId  = Context.User.Id
                };
            }

            int hours = 164;

            if (PremiumDb.IsPremium(Context.Guild.Id, ProType.Guild) || PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
            {
                hours /= 2;
            }

            if (weekly.Date.AddHours(hours).CompareTo(DateTime.Now) < 0)
            {
                int streak = await DailyDb.GetHighest(Context.Guild.Id) + 15;

                int amount = ToastieUtil.DailyAmount(streak);
                int tax    = ToastieUtil.DailyTax(amount, BalanceDb.GetToasties(Context.User.Id, Context.Guild.Id), BalanceDb.GetToasties(Context.Client.CurrentUser.Id, Context.Guild.Id), await BalanceDb.TotalToasties(Context.Guild.Id));
                amount -= tax / 2;
                if (PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
                {
                    amount += 1000;
                }

                string text = "";
                if (PremiumDb.IsPremium(Context.User.Id, ProType.ProPlus))
                {
                    await LootBoxDb.AddLootbox(Context.User.Id, LootBoxType.WaifuT1, 1, Context.Guild.Id);

                    text = "You receive a T1 Waifu lootbox! :star2:";
                }

                await BalanceDb.AddToasties(Context.User.Id, amount, Context.Guild.Id);

                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, tax / 2, Context.Guild.Id);

                weekly.Date = DateTime.Now;
                await WeeklyDb.SetWeekly(weekly);

                await Context.Channel.SendMessageAsync(text, false, ToastieUtil.WeeklyGetEmbed(amount, BalanceDb.GetToasties(Context.User.Id, Context.Guild.Id), Context.User, Program.GetPrefix(Context)).Build());

                return;
            }

            await Context.Channel.SendMessageAsync("", false, ToastieUtil.WeeklyWaitEmbed(weekly.Date.AddHours(hours), Context.User, Program.GetPrefix(Context)).Build());
        }
예제 #3
0
        public async Task Lootboxes([Remainder] IUser user = null)
        {
            user ??= Context.User;

            var boxes = await LootBoxDb.GetAll(user.Id, Context.Guild.Id);

            if (boxes.Count == 0)
            {
                await Context.Channel.SendMessageAsync("", false, ToastieUtil.NoBoxEmbed(user).Build());

                return;
            }

            await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxListEmbed(boxes, user).WithDescription("").Build());
        }
예제 #4
0
        public async Task BulkOpen([Remainder] string str = "")
        {
            var boxes = await LootBoxDb.GetAll(Context.User.Id, Context.Guild.Id);

            if (boxes.Count == 0)
            {
                await Context.Channel.SendMessageAsync("", false, ToastieUtil.NoBoxEmbed(Context.User).Build());

                return;
            }

            LootBox box = null;

            if (boxes.Count == 1)
            {
                box = boxes[0];
            }

            else
            {
                var listMsg = await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxListEmbed(boxes, Context.User)
                                                                     .WithFooter("Times out in 23 seconds")
                                                                     .WithDescription("Enter the number of the Lootbox type you wish to open.")
                                                                     .Build());

                var response = await NextMessageAsync(
                    new Criteria <IMessage>()
                    .AddCriterion(new EnsureSourceUserCriterion())
                    .AddCriterion(new EnsureSourceChannelCriterion())
                    .AddCriterion(new EnsureRangeCriterion(boxes.Count, Program.GetPrefix(Context))),
                    new TimeSpan(0, 0, 23));

                _ = listMsg.DeleteAsync();
                int i = 0;
                try
                {
                    i = int.Parse(response.Content);
                }
                catch
                {
                    _ = Context.Message.DeleteAsync();
                    return;
                }
                _ = response.DeleteAsync();

                box = boxes[i - 1];
            }

            var type      = LootboxStats.Lootboxes[box.Type];
            var dialoague = await ReplyAsync(embed : new EmbedBuilderPrepared(Context.User).WithDescription($"How many {type.Emote} **{type.Name}** lootboxes do you wish to open?").Build());

            var amountMsg = await NextMessageAsync(
                new Criteria <IMessage>()
                .AddCriterion(new EnsureSourceUserCriterion())
                .AddCriterion(new EnsureSourceChannelCriterion())
                .AddCriterion(new EnsureRangeCriterion(int.MaxValue, Program.GetPrefix(Context))),
                new TimeSpan(0, 0, 23));

            int amount;

            try
            {
                amount = int.Parse(amountMsg.Content);
            }
            catch
            {
                _ = Context.Message.DeleteAsync();
                return;
            }
            _ = dialoague.DeleteAsync();

            try
            {
                await LootBoxDb.AddLootbox(Context.User.Id, box.Type, -amount, box.GuildId);
            }
            catch
            {
                await Context.Channel.SendMessageAsync("You tried.");

                return;
            }
            _ = amountMsg.DeleteAsync();

            var msg = await Context.Channel.SendMessageAsync("", false, ToastieUtil.BoxOpeningEmbed(Context.User).Build());

            await ProfileDb.IncrementLootboxOpened(Context.User.Id, amount);

            int waitms = 4200;

            int  toasties    = 0;
            var  waifusFound = new List <Waifu>();
            var  waifus      = UserInventoryDb.GetWaifus(Context.User.Id, Context.Guild.Id);
            bool isPremium   = PremiumDb.IsPremium(Context.User.Id, ProType.Pro);

            for (int i = 0; i < amount; i++)
            {
                if (type.IsWaifu())
                {
                    var waifu = await ToastieUtil.UnboxWaifu(type, isPremium, Context.User.Id, Context.Guild.Id);

                    while (waifu == null || waifus.Any(x => x.Name.Equals(waifu.Name)) || waifusFound.Any(x => x.Name.Equals(waifu.Name)))
                    {
                        waifu = await ToastieUtil.UnboxWaifu(type, isPremium, Context.User.Id, Context.Guild.Id);
                    }

                    waifusFound.Add(waifu);
                    await UserInventoryDb.AddWaifu(Context.User.Id, waifu, Context.Guild.Id);
                }
                else
                {
                    toasties += type.GetRandomToasties();
                }
            }

            await BalanceDb.AddToasties(Context.User.Id, toasties, Context.Guild.Id);

            var bal = BalanceDb.GetToasties(Context.User.Id, Context.Guild.Id);

            await Task.Delay(waitms);

            var eb = new EmbedBuilder()
                     .WithAuthor($"{Context.User} | {box.Type.ToString()} x{amount}", Context.User.GetAvatarUrl(), LinkHelper.GetRedirectUrl(LinkHelper.Patreon, "Patreon", "cmd-embed-lootbox"))
                     .WithColor(BasicUtil.RandomColor())
                     .WithThumbnailUrl("https://i.imgur.com/4JQmxa6.png");

            string desc = $"You found **{toasties.ToString("n0")}** {ToastieUtil.RandomEmote()}!\nNow you have **{bal.ToString("n0")}** {ToastieUtil.RandomEmote()}!\n\n";

            if (waifusFound.Any())
            {
                desc += "**Waifus Found:**\n";
                foreach (var w in waifusFound)
                {
                    desc += $"`T{w.Tier}` **{w.Name}** - *{(w.Source.Length > 37 ? w.Source.Substring(0, 33) + "..." : w.Source)}*\n";
                }
            }

            eb.WithDescription(desc.Length > 2000 ? desc.Substring(0, 1970) + "\n*And more...*" : desc);
            await msg.ModifyAsync(x => {
                x.Embed = eb.Build();
            });
        }
예제 #5
0
        public async Task Open([Remainder] string str = "")
        {
            var boxes = await LootBoxDb.GetAll(Context.User.Id, Context.Guild.Id);

            if (boxes.Count == 0)
            {
                await Context.Channel.SendMessageAsync("", false, ToastieUtil.NoBoxEmbed(Context.User).Build());

                return;
            }

            LootBox box = null;

            if (boxes.Count == 1)
            {
                box = boxes[0];
            }

            else
            {
                var listMsg = await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxListEmbed(boxes, Context.User)
                                                                     .WithFooter("Times out in 23 seconds")
                                                                     .WithDescription("Enter the number of the Lootbox you wish to open.")
                                                                     .Build());

                var response = await NextMessageAsync(
                    new Criteria <IMessage>()
                    .AddCriterion(new EnsureSourceUserCriterion())
                    .AddCriterion(new EnsureSourceChannelCriterion())
                    .AddCriterion(new EnsureRangeCriterion(boxes.Count, Program.GetPrefix(Context))),
                    new TimeSpan(0, 0, 23));

                _ = listMsg.DeleteAsync();
                int i = 0;
                try
                {
                    i = int.Parse(response.Content);
                }
                catch
                {
                    _ = Context.Message.DeleteAsync();
                    return;
                }
                _ = response.DeleteAsync();

                box = boxes[i - 1];
            }

            var type = LootboxStats.Lootboxes[box.Type];

            try
            {
                await LootBoxDb.AddLootbox(Context.User.Id, box.Type, -1, box.GuildId);
            } catch
            {
                await Context.Channel.SendMessageAsync("You tried.");

                return;
            }
            var msg = await Context.Channel.SendMessageAsync("", false, ToastieUtil.BoxOpeningEmbed(Context.User).Build());

            await ProfileDb.IncrementLootboxOpened(Context.User.Id);

            int waitms = 4200;

            if (type.IsWaifu())
            {
                bool isPremium = PremiumDb.IsPremium(Context.User.Id, ProType.Pro);
                var  waifu     = await ToastieUtil.UnboxWaifu(type, isPremium, Context.User.Id, Context.Guild.Id);

                while (UserInventoryDb.OwnsWaifu(Context.User.Id, waifu, Context.Guild.Id))
                {
                    waifu = await ToastieUtil.UnboxWaifu(type, isPremium, Context.User.Id, Context.Guild.Id);
                }

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

                await Task.Delay(waitms);

                var embed = WaifuUtil.WaifuEmbedBuilder(waifu, Context).Build();
                await msg.ModifyAsync(x => {
                    x.Embed   = embed;
                    x.Content = $"{Context.User.Mention} Congratulations! You found **{waifu.Name}**!";
                });

                return;
            }

            var amountWon = type.GetRandomToasties();
            await BalanceDb.AddToasties(Context.User.Id, amountWon, Context.Guild.Id);

            var bal = BalanceDb.GetToasties(Context.User.Id, Context.Guild.Id);
            await Task.Delay(waitms);

            await msg.ModifyAsync(x => {
                x.Embed = new EmbedBuilder()
                          .WithAuthor($"{Context.User} | {box.Type.ToString()}", Context.User.GetAvatarUrl(), LinkHelper.GetRedirectUrl(LinkHelper.Patreon, "Patreon", "cmd-embed-lootbox"))
                          .WithColor(BasicUtil.RandomColor())
                          .WithThumbnailUrl("https://i.imgur.com/4JQmxa6.png")
                          .WithDescription($"Congratulations! You found **{amountWon.ToString("n0")}** {ToastieUtil.RandomEmote()}!\nNow you have **{bal.ToString("n0")}** {ToastieUtil.RandomEmote()}!")
                          .Build();
            });
        }
예제 #6
0
        public async Task BuyLootbox([Remainder] string str = "")
        {
            var prefix = Program.GetPrefix(Context);

            if (!PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
            {
                await Context.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(Context.User)
                                                       .WithDescription($"*~ This command requires Pro Guild+ ~*\n" +
                                                                        $"Try `{prefix}lootboxstats` to see drop rates.")
                                                       .WithFooter($"`{prefix}pro`")
                                                       .Build());

                return;
            }

            LootboxStat box   = null;
            var         boxes = LootboxStats.Lootboxes.Where(x => x.Value.Price >= 0).Select(x => x.Value).ToList();

            if (str != "")
            {
                var matches = boxes.Where(x => x.Name.Contains(str, StringComparison.OrdinalIgnoreCase));
                if (matches.Count() == 1)
                {
                    box = matches.First();
                }
            }
            if (box == null)
            {
                var listMsg = await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxShopEmbed(Context.User)
                                                                     .WithFooter("Times out in 23 seconds. Try the `lootboxstats` command")
                                                                     .WithDescription("Enter the number of the lootbox you wish to purchase.")
                                                                     .Build());

                var response = await NextMessageAsync(
                    new Criteria <IMessage>()
                    .AddCriterion(new EnsureSourceUserCriterion())
                    .AddCriterion(new EnsureSourceChannelCriterion())
                    .AddCriterion(new EnsureRangeCriterion(boxes.Count(), Program.GetPrefix(Context))),
                    new TimeSpan(0, 0, 23));

                _ = listMsg.DeleteAsync();
                int i = 0;
                try
                {
                    i = int.Parse(response.Content);
                }
                catch
                {
                    _ = Context.Message.DeleteAsync();
                    return;
                }
                _ = response.DeleteAsync();

                box = boxes[i - 1];
            }

            var msg = await Context.Channel.SendMessageAsync($"How many **{box.Name}** lootboxes do you wish to buy? (max 100)");

            var resp = await NextMessageAsync(
                new Criteria <IMessage>()
                .AddCriterion(new EnsureSourceUserCriterion())
                .AddCriterion(new EnsureSourceChannelCriterion())
                .AddCriterion(new EnsureRangeCriterion(100, Program.GetPrefix(Context))),
                new TimeSpan(0, 0, 23));

            _ = msg.DeleteAsync();
            int amount = 0;

            try
            {
                amount = int.Parse(resp.Content);
            }
            catch
            {
                _ = Context.Message.DeleteAsync();
                return;
            }
            _ = resp.DeleteAsync();

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

                return;
            }

            await LootBoxDb.AddLootbox(Context.User.Id, (LootBoxType)box.TypeId, amount, Context.Guild.Id);

            await Context.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(Context.User)
                                                   .WithDescription($"You bought {amount}x **{box.Name}**!\nType `{Program.GetPrefix(Context)}open` to open it!")
                                                   .Build());
        }