Esempio n. 1
0
        public async Task SetProfileBackColorAsync(CommandContext e)
        {
            var  context = e.GetService <MikiDbContext>();
            User user    = await DatabaseHelpers.GetUserAsync(context, e.Author);

            var x = Regex.Matches(e.Arguments.Pack.TakeAll().ToUpper(), "(#)?([A-F0-9]{6})");

            if (x.Count > 0)
            {
                ProfileVisuals visuals = await ProfileVisuals.GetAsync(e.Author.Id, context);

                var hex = x.First().Groups.Last().Value;

                visuals.BackgroundColor = hex;
                user.RemoveCurrency(250);
                await context.SaveChangesAsync();

                await e.SuccessEmbed($"Your foreground color has been successfully changed to `{hex}`")
                .QueueToChannelAsync(e.Channel);
            }
            else
            {
                await new EmbedBuilder()
                .SetTitle("🖌 Setting a background color!")
                .SetDescription("Changing your background color costs 250 mekos. use `>setbackcolor (e.g. #00FF00)` to purchase")
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
        }
Esempio n. 2
0
        private async Task ConfirmBuyMarriageSlot(EventContext cont, int costForUpgrade)
        {
            using (var context = new MikiContext())
            {
                User user = await DatabaseHelpers.GetUserAsync(context, cont.Author);

                if (user.Currency >= costForUpgrade)
                {
                    user.MarriageSlots++;
                    user.Currency -= costForUpgrade;

                    new EmbedBuilder()
                    {
                        Color       = new Color(0.4f, 1f, 0.6f),
                        Description = cont.Locale.GetString("buymarriageslot_success", user.MarriageSlots),
                    }.ToEmbed().QueueToChannel(cont.Channel);

                    await context.SaveChangesAsync();

                    await cont.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(cont.Author.Id, cont.Channel.Id);
                }
                else
                {
                    new EmbedBuilder()
                    {
                        Color       = new Color(1, 0.4f, 0.6f),
                        Description = cont.Locale.GetString("buymarriageslot_insufficient_mekos", (costForUpgrade - user.Currency)),
                    }.ToEmbed().QueueToChannel(cont.Channel);
                    await cont.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(cont.Author.Id, cont.Channel.Id);
                }
            }
        }
Esempio n. 3
0
        public async Task SetProfileForeColorAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await DatabaseHelpers.GetUserAsync(context, e.Author);

                var x = Regex.Matches(e.Arguments.ToString().ToUpper(), "(#)?([A-F0-9]{6})");

                if (x.Count > 0)
                {
                    ProfileVisuals visuals = await ProfileVisuals.GetAsync(e.Author.Id, context);

                    var hex = x.First().Groups.Last().Value;

                    visuals.ForegroundColor = hex;
                    user.RemoveCurrency(250);
                    await context.SaveChangesAsync();

                    e.SuccessEmbed($"Your foreground color has been successfully changed to `{hex}`")
                    .QueueToChannel(e.Channel);
                }
                else
                {
                    new EmbedBuilder()
                    .SetTitle("🖌 Setting a foreground color!")
                    .SetDescription("Changing your foreground(text) color costs 250 mekos. use `>setfrontcolor (e.g. #00FF00)` to purchase")
                    .ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }
Esempio n. 4
0
        public async Task BuyMarriageSlotAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await DatabaseHelpers.GetUserAsync(context, e.Author);

                int  limit     = 10;
                bool isDonator = await user.IsDonatorAsync(context);

                if (isDonator)
                {
                    limit += 5;
                }

                if (user.MarriageSlots >= limit)
                {
                    EmbedBuilder embed = Utils.ErrorEmbed(e, "For now, **{limit} slots** is the max. sorry :(");

                    if (limit == 10 && !isDonator)
                    {
                        embed.AddField("Pro tip!", "Donators get 5 more slots!")
                        .SetFooter("Check `>donate` for more information!");
                    }

                    embed.Color = new Color(1f, 0.6f, 0.4f);
                    await embed.ToEmbed().QueueToChannelAsync(e.Channel);

                    return;
                }

                int costForUpgrade = (user.MarriageSlots - 4) * 2500;

                if (user.Currency >= costForUpgrade)
                {
                    user.MarriageSlots++;
                    user.Currency -= costForUpgrade;

                    await new EmbedBuilder()
                    {
                        Color       = new Color(0.4f, 1f, 0.6f),
                        Description = e.Locale.GetString("buymarriageslot_success", user.MarriageSlots),
                    }.ToEmbed().QueueToChannelAsync(e.Channel);

                    await context.SaveChangesAsync();

                    await e.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(e.Author.Id, e.Channel.Id);
                }
                else
                {
                    await new EmbedBuilder()
                    {
                        Color       = new Color(1, 0.4f, 0.6f),
                        Description = e.Locale.GetString("buymarriageslot_insufficient_mekos", (costForUpgrade - user.Currency)),
                    }.ToEmbed().QueueToChannelAsync(e.Channel);
                    await e.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(e.Author.Id, e.Channel.Id);
                }
            }
        }
Esempio n. 5
0
        public async Task GiveMekosAsync(ICommandContext e)
        {
            if (e.Arguments.Take(out string userName))
            {
                var user = await DiscordExtensions.GetUserAsync(userName, e.Guild);

                if (user == null)
                {
                    await e.ErrorEmbedResource("give_error_no_mention")
                    .ToEmbed().QueueToChannelAsync(e.Channel);

                    return;
                }

                if (!e.Arguments.Take(out int amount))
                {
                    await e.ErrorEmbedResource("give_error_amount_unparsable")
                    .ToEmbed().QueueToChannelAsync(e.Channel);

                    return;
                }

                var context = e.GetService <MikiDbContext>();

                User sender = await DatabaseHelpers.GetUserAsync(context, e.Author);

                User receiver = await DatabaseHelpers.GetUserAsync(context, user);

                if (amount <= sender.Currency)
                {
                    sender.RemoveCurrency(amount);

                    if (await receiver.IsBannedAsync(context))
                    {
                        throw new UserNullException();
                    }

                    await receiver.AddCurrencyAsync(amount);

                    await new EmbedBuilder()
                    {
                        Title       = "🔸 transaction",
                        Description = e.Locale.GetString("give_description",
                                                         sender.Name,
                                                         receiver.Name,
                                                         amount.ToFormattedString()),
                        Color = new Color(255, 140, 0),
                    }.ToEmbed().QueueToChannelAsync(e.Channel);
                    await context.SaveChangesAsync();
                }
                else
                {
                    throw new InsufficientCurrencyException(sender.Currency, amount);
                }
            }
        }
Esempio n. 6
0
        public async Task GiveMekosAsync(EventContext e)
        {
            IDiscordUser user = null;

            if (e.Arguments.Take(out string userName))
            {
                user = await DiscordExtensions.GetUserAsync(userName, e.Guild);

                if (user == null)
                {
                    await e.ErrorEmbedResource("give_error_no_mention")
                    .ToEmbed().QueueToChannelAsync(e.Channel);

                    return;
                }

                if (!e.Arguments.Take(out int amount))
                {
                    await e.ErrorEmbedResource("give_error_amount_unparsable")
                    .ToEmbed().QueueToChannelAsync(e.Channel);

                    return;
                }

                using (MikiContext context = new MikiContext())
                {
                    User sender = await DatabaseHelpers.GetUserAsync(context, e.Author);

                    User receiver = await DatabaseHelpers.GetUserAsync(context, user);

                    if (amount <= sender.Currency)
                    {
                        sender.RemoveCurrency(amount);
                        await receiver.AddCurrencyAsync(amount);

                        await new EmbedBuilder()
                        {
                            Title       = "🔸 transaction",
                            Description = e.Locale.GetString("give_description", sender.Name, receiver.Name, amount.ToFormattedString()),
                            Color       = new Color(255, 140, 0),
                        }.ToEmbed().QueueToChannelAsync(e.Channel);

                        await context.SaveChangesAsync();
                    }
                    else
                    {
                        await e.ErrorEmbedResource("user_error_insufficient_mekos")
                        .ToEmbed().QueueToChannelAsync(e.Channel);
                    }
                }
            }
        }
Esempio n. 7
0
        public async Task BuyMarriageSlotAsync(CommandContext e)
        {
            var context = e.GetService <MikiDbContext>();

            User user = await DatabaseHelpers.GetUserAsync(context, e.Author);

            int  limit     = 10;
            bool isDonator = await user.IsDonatorAsync(context);

            if (isDonator)
            {
                limit += 5;
            }

            if (user.MarriageSlots >= limit)
            {
                EmbedBuilder embed = Utils.ErrorEmbed(e, $"For now, **{limit} slots** is the max. sorry :(");

                if (limit == 10 && !isDonator)
                {
                    embed.AddField("Pro tip!", "Donators get 5 more slots!")
                    .SetFooter("Check `>donate` for more information!");
                }

                embed.Color = new Color(1f, 0.6f, 0.4f);
                await embed.ToEmbed().QueueToChannelAsync(e.Channel);

                return;
            }

            int costForUpgrade = (user.MarriageSlots - 4) * 2500;

            user.MarriageSlots++;
            user.RemoveCurrency(costForUpgrade);

            await new EmbedBuilder()
            {
                Color       = new Color(0.4f, 1f, 0.6f),
                Description = e.Locale.GetString("buymarriageslot_success", user.MarriageSlots),
            }.ToEmbed().QueueToChannelAsync(e.Channel);

            await context.SaveChangesAsync();
        }
Esempio n. 8
0
        public async Task BuyMarriageSlotAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await DatabaseHelpers.GetUserAsync(context, e.Author);

                int  limit     = 10;
                bool isDonator = await user.IsDonatorAsync(context);

                if (isDonator)
                {
                    limit += 5;
                }

                EmbedBuilder embed = new EmbedBuilder();

                if (user.MarriageSlots >= limit)
                {
                    embed.Description = $"For now, **{limit} slots** is the max. sorry :(";

                    if (limit == 10 && !isDonator)
                    {
                        embed.AddField("Pro tip!", "Donators get 5 more slots!")
                        .SetFooter("Check `>donate` for more information!", "");
                    }

                    embed.Color = new Color(1f, 0.6f, 0.4f);
                    embed.ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                int costForUpgrade = (user.MarriageSlots - 4) * 2500;

                await ConfirmBuyMarriageSlot(e, costForUpgrade);
            }
        }
Esempio n. 9
0
        public async Task MarryAsync(EventContext e)
        {
            long askerId    = 0;
            long receiverId = 0;

            ArgObject args = e.Arguments.FirstOrDefault();

            if (args == null)
            {
                return;
            }

            IDiscordGuildUser user = await args.GetUserAsync(e.Guild);

            if (user == null)
            {
                e.Channel.QueueMessageAsync("Couldn't find this person..");
                return;
            }

            if (user.Id == (await e.Guild.GetSelfAsync()).Id)
            {
                e.Channel.QueueMessageAsync("(´・ω・`)");
                return;
            }

            using (MikiContext context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                User mentionedPerson = await User.GetAsync(context, user.Id.ToDbLong(), user.Username);

                User currentUser = await DatabaseHelpers.GetUserAsync(context, e.Author);

                askerId    = currentUser.Id;
                receiverId = mentionedPerson.Id;

                if (currentUser == null || mentionedPerson == null)
                {
                    e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (mentionedPerson.Banned)
                {
                    e.ErrorEmbed("This person has been banned from Miki.").ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (mentionedPerson.Id == currentUser.Id)
                {
                    e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (await repository.ExistsAsync(mentionedPerson.Id, currentUser.Id))
                {
                    e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_exists")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                await repository.ProposeAsync(askerId, receiverId);

                await context.SaveChangesAsync();
            }

            new EmbedBuilder()
            .SetTitle("💍" + e.Locale.GetString("miki_module_accounts_marry_text", $"**{e.Author.Username}**", $"**{user.Username}**"))
            .SetDescription(e.Locale.GetString("miki_module_accounts_marry_text2", user.Username, e.Author.Username))
            .SetColor(0.4f, 0.4f, 0.8f)
            .SetThumbnail("https://i.imgur.com/TKZSKIp.png")
            .AddInlineField("✅ To accept", $">acceptmarriage @user")
            .AddInlineField("❌ To decline", $">declinemarriage @user")
            .SetFooter("Take your time though! This proposal won't disappear", "")
            .ToEmbed().QueueToChannel(e.Channel);
        }
Esempio n. 10
0
        public async Task AcceptMarriageAsync(EventContext e)
        {
            IDiscordUser user = await e.Arguments.Join().GetUserAsync(e.Guild);

            if (user == null)
            {
                e.ErrorEmbed("I couldn't find this user!")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            if (user.Id == e.Author.Id)
            {
                e.ErrorEmbed("Please mention someone else than yourself.")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            using (var context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                User accepter = await DatabaseHelpers.GetUserAsync(context, e.Author);

                User asker = await DatabaseHelpers.GetUserAsync(context, user);

                UserMarriedTo marriage = await repository.GetEntryAsync(accepter.Id, asker.Id);

                if (marriage != null)
                {
                    if (accepter.MarriageSlots < (await repository.GetMarriagesAsync(accepter.Id)).Count)
                    {
                        throw new InsufficientMarriageSlotsException(accepter);
                    }

                    if (asker.MarriageSlots < (await repository.GetMarriagesAsync(asker.Id)).Count)
                    {
                        throw new InsufficientMarriageSlotsException(asker);
                    }

                    if (marriage.ReceiverId != e.Author.Id.ToDbLong())
                    {
                        e.Channel.QueueMessageAsync($"You can not accept your own responses!");
                        return;
                    }

                    if (marriage.Marriage.IsProposing)
                    {
                        marriage.Marriage.AcceptProposal();

                        await context.SaveChangesAsync();

                        new EmbedBuilder()
                        {
                            Title       = ("❤️ Happily married"),
                            Color       = new Color(190, 25, 49),
                            Description = ($"Much love to { e.Author.Username } and { user.Username } in their future adventures together!")
                        }.ToEmbed().QueueToChannel(e.Channel);
                    }
                    else
                    {
                        e.ErrorEmbed("You're already married to this person ya doofus!")
                        .ToEmbed().QueueToChannel(e.Channel);
                    }
                }
                else
                {
                    e.Channel.QueueMessageAsync("This user hasn't proposed to you!");
                    return;
                }
            }
        }
Esempio n. 11
0
        public async Task GetDailyAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User u = await DatabaseHelpers.GetUserAsync(context, e.Author);

                if (u == null)
                {
                    e.ErrorEmbed(e.Locale.GetString("user_error_no_account"))
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                int dailyAmount       = 100;
                int dailyStreakAmount = 20;

                if (await u.IsDonatorAsync(context))
                {
                    dailyAmount       *= 2;
                    dailyStreakAmount *= 2;
                }

                if (u.LastDailyTime.AddHours(23) >= DateTime.Now)
                {
                    var time = (u.LastDailyTime.AddHours(23) - DateTime.Now).ToTimeString(e.Locale);

                    e.ErrorEmbed($"You already claimed your daily today! Please wait another `{time}` before using it again.")
                    .AddInlineField("Appreciate Miki?", "Vote for us every day on [DiscordBots](https://discordbots.org/bot/160105994217586689/vote) to show your thanks!")
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                int    streak   = 0;
                string redisKey = $"user:{e.Author.Id}:daily";

                if (await Global.RedisClient.ExistsAsync(redisKey))
                {
                    streak = await Global.RedisClient.GetAsync <int>(redisKey);

                    streak++;
                }

                int amount = dailyAmount + (dailyStreakAmount * Math.Min(100, streak));

                await u.AddCurrencyAsync(amount);

                u.LastDailyTime = DateTime.Now;

                var embed = new EmbedBuilder()
                            .SetTitle("💰 Daily")
                            .SetDescription(e.Locale.GetString("daily_received", $"**{amount.ToFormattedString()}**", $"`{u.Currency.ToFormattedString()}`"))
                            .SetColor(253, 216, 136);

                if (streak > 0)
                {
                    embed.AddInlineField("Streak!", $"You're on a {streak.ToFormattedString()} day daily streak!");
                }

                embed.ToEmbed().QueueToChannel(e.Channel);

                await Global.RedisClient.UpsertAsync(redisKey, streak, new TimeSpan(48, 0, 0));

                await context.SaveChangesAsync();
            }
        }
Esempio n. 12
0
        public async Task GiveMekosAsync(EventContext e)
        {
            if (e.Arguments.Count < 2)
            {
                e.ErrorEmbedResource("give_error_no_arg")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            ArgObject arg = e.Arguments.FirstOrDefault();

            IDiscordUser user = null;

            if (arg != null)
            {
                user = await arg.GetUserAsync(e.Guild);
            }

            if (user == null)
            {
                e.ErrorEmbedResource("give_error_no_mention")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            arg = arg.Next();

            int?amount = arg?.TakeInt() ?? null;

            if (amount == null)
            {
                e.ErrorEmbedResource("give_error_amount_unparsable")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            using (MikiContext context = new MikiContext())
            {
                User sender = await DatabaseHelpers.GetUserAsync(context, e.Author);

                User receiver = await DatabaseHelpers.GetUserAsync(context, user);

                if (amount.Value <= sender.Currency)
                {
                    sender.RemoveCurrency(amount.Value);
                    await receiver.AddCurrencyAsync(amount.Value);

                    new EmbedBuilder()
                    {
                        Title       = "🔸 transaction",
                        Description = e.Locale.GetString("give_description", sender.Name, receiver.Name, amount.Value.ToFormattedString()),
                        Color       = new Color(255, 140, 0),
                    }.ToEmbed().QueueToChannel(e.Channel);

                    await context.SaveChangesAsync();
                }
                else
                {
                    e.ErrorEmbedResource("user_error_insufficient_mekos")
                    .ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }
Esempio n. 13
0
        public async Task GiveReputationAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                var repObject = await Global.RedisClient.GetAsync <ReputationObject>($"user:{giver.Id}:rep");

                if (repObject == null)
                {
                    repObject = new ReputationObject()
                    {
                        LastReputationGiven  = DateTime.Now,
                        ReputationPointsLeft = 3
                    };

                    await Global.RedisClient.UpsertAsync(
                        $"user:{giver.Id}:rep",
                        repObject,
                        DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow
                        );
                }

                ArgObject arg = e.Arguments.FirstOrDefault();

                if (arg == null)
                {
                    TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now);

                    new EmbedBuilder()
                    {
                        Title       = e.Locale.GetString("miki_module_accounts_rep_header"),
                        Description = e.Locale.GetString("miki_module_accounts_rep_description")
                    }.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToFormattedString())
                    .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Locale).ToString())
                    .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft.ToString())
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }
                else
                {
                    Dictionary <IDiscordUser, short> usersMentioned = new Dictionary <IDiscordUser, short>();

                    EmbedBuilder embed = new EmbedBuilder();

                    int  totalAmountGiven = 0;
                    bool mentionedSelf    = false;

                    while (true || totalAmountGiven <= repObject.ReputationPointsLeft)
                    {
                        if (arg == null)
                        {
                            break;
                        }

                        IDiscordUser u = await arg.GetUserAsync(e.Guild);

                        short amount = 1;

                        if (u == null)
                        {
                            break;
                        }

                        arg = arg?.Next();

                        if ((arg?.TakeInt() ?? -1) != -1)
                        {
                            amount = (short)arg.TakeInt().Value;
                            arg    = arg.Next();
                        }
                        else if (Utils.IsAll(arg))
                        {
                            amount = repObject.ReputationPointsLeft;
                            arg    = arg.Next();
                        }

                        if (u.Id == e.Author.Id)
                        {
                            mentionedSelf = true;
                            continue;
                        }

                        totalAmountGiven += amount;

                        if (usersMentioned.Keys.Where(x => x.Id == u.Id).Count() > 0)
                        {
                            usersMentioned[usersMentioned.Keys.Where(x => x.Id == u.Id).First()] += amount;
                        }
                        else
                        {
                            usersMentioned.Add(u, amount);
                        }
                    }

                    if (mentionedSelf)
                    {
                        embed.Footer = new EmbedFooter()
                        {
                            Text = e.Locale.GetString("warning_mention_self"),
                        };
                    }

                    if (usersMentioned.Count == 0)
                    {
                        return;
                    }
                    else
                    {
                        if (totalAmountGiven <= 0)
                        {
                            e.ErrorEmbedResource("miki_module_accounts_rep_error_zero")
                            .ToEmbed().QueueToChannel(e.Channel);
                            return;
                        }

                        if (usersMentioned.Sum(x => x.Value) > repObject.ReputationPointsLeft)
                        {
                            e.ErrorEmbedResource("error_rep_limit", usersMentioned.Count, usersMentioned.Sum(x => x.Value), repObject.ReputationPointsLeft)
                            .ToEmbed().QueueToChannel(e.Channel);
                            return;
                        }
                    }

                    embed.Title       = (e.Locale.GetString("miki_module_accounts_rep_header"));
                    embed.Description = (e.Locale.GetString("rep_success"));

                    foreach (var user in usersMentioned)
                    {
                        User receiver = await DatabaseHelpers.GetUserAsync(context, user.Key);

                        receiver.Reputation += user.Value;

                        embed.AddInlineField(
                            receiver.Name,
                            string.Format("{0} => {1} (+{2})", (receiver.Reputation - user.Value).ToFormattedString(), receiver.Reputation.ToFormattedString(), user.Value)
                            );
                    }

                    repObject.ReputationPointsLeft -= (short)usersMentioned.Sum(x => x.Value);

                    await Global.RedisClient.UpsertAsync(
                        $"user:{giver.Id}:rep",
                        repObject,
                        DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow
                        );

                    embed.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft.ToString())
                    .ToEmbed().QueueToChannel(e.Channel);

                    await context.SaveChangesAsync();
                }
            }
        }
Esempio n. 14
0
        public async Task GetDailyAsync(CommandContext e)
        {
            var context = e.GetService <MikiDbContext>();

            User u = await DatabaseHelpers.GetUserAsync(context, e.Author);

            if (u == null)
            {
                await e.ErrorEmbed(e.Locale.GetString("user_error_no_account"))
                .ToEmbed().QueueToChannelAsync(e.Channel);

                return;
            }

            int dailyAmount       = 100;
            int dailyStreakAmount = 20;

            if (await u.IsDonatorAsync(context))
            {
                dailyAmount       *= 2;
                dailyStreakAmount *= 2;
            }

            if (u.LastDailyTime.AddHours(23) >= DateTime.Now)
            {
                var time = (u.LastDailyTime.AddHours(23) - DateTime.Now).ToTimeString(e.Locale);

                var builder = e.ErrorEmbed($"You already claimed your daily today! Please wait another `{time}` before using it again.");

                switch (MikiRandom.Next(2))
                {
                case 0:
                {
                    builder.AddInlineField("Appreciate Miki?", "Vote for us every day on [DiscordBots](https://discordbots.org/bot/160105994217586689/vote) to get an additional bonus!");
                }
                break;

                case 1:
                {
                    builder.AddInlineField("Appreciate Miki?", "Donate to us on [Patreon](https://patreon.com/mikibot) for more mekos!");
                }
                break;
                }
                await builder.ToEmbed()
                .QueueToChannelAsync(e.Channel);

                return;
            }

            int    streak   = 0;
            string redisKey = $"user:{e.Author.Id}:daily";

            var cache = e.GetService <ICacheClient>();

            if (await cache.ExistsAsync(redisKey))
            {
                streak = await cache.GetAsync <int>(redisKey);

                streak++;
            }

            int amount = dailyAmount + (dailyStreakAmount * Math.Min(100, streak));

            await u.AddCurrencyAsync(amount);

            u.LastDailyTime = DateTime.Now;

            var embed = new EmbedBuilder()
                        .SetTitle("💰 Daily")
                        .SetDescription(e.Locale.GetString("daily_received", $"**{amount.ToFormattedString()}**", $"`{u.Currency.ToFormattedString()}`"))
                        .SetColor(253, 216, 136);

            if (streak > 0)
            {
                embed.AddInlineField("Streak!", $"You're on a {streak.ToFormattedString()} day daily streak!");
            }

            await embed.ToEmbed().QueueToChannelAsync(e.Channel);

            await cache.UpsertAsync(redisKey, streak, new TimeSpan(48, 0, 0));

            await context.SaveChangesAsync();
        }
Esempio n. 15
0
        public async Task GiveReputationAsync(CommandContext e)
        {
            var context = e.GetService <MikiDbContext>();

            User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong());

            var cache = e.GetService <ICacheClient>();

            var repObject = await cache.GetAsync <ReputationObject>($"user:{giver.Id}:rep");

            if (repObject == null)
            {
                repObject = new ReputationObject()
                {
                    LastReputationGiven  = DateTime.Now,
                    ReputationPointsLeft = 3
                };

                await cache.UpsertAsync(
                    $"user:{giver.Id}:rep",
                    repObject,
                    DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow
                    );
            }

            if (!e.Arguments.CanTake)
            {
                TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now);

                await new EmbedBuilder()
                {
                    Title       = e.Locale.GetString("miki_module_accounts_rep_header"),
                    Description = e.Locale.GetString("miki_module_accounts_rep_description")
                }.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToFormattedString())
                .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Locale).ToString())
                .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft.ToString())
                .ToEmbed().QueueToChannelAsync(e.Channel);
                return;
            }
            else
            {
                Dictionary <IDiscordUser, short> usersMentioned = new Dictionary <IDiscordUser, short>();

                EmbedBuilder embed = new EmbedBuilder();

                int  totalAmountGiven = 0;
                bool mentionedSelf    = false;

                while (e.Arguments.CanTake && totalAmountGiven <= repObject.ReputationPointsLeft)
                {
                    short amount = 1;

                    e.Arguments.Take(out string userName);

                    var u = await DiscordExtensions.GetUserAsync(userName, e.Guild);

                    if (u == null)
                    {
                        throw new UserNullException();
                    }

                    if (e.Arguments.Take(out int value))
                    {
                        if (value > 0)
                        {
                            amount = (short)value;
                        }
                    }
                    else if (e.Arguments.Peek(out string arg))
                    {
                        if (Utils.IsAll(arg))
                        {
                            amount = (short)(repObject.ReputationPointsLeft - ((short)usersMentioned.Sum(x => x.Value)));
                            e.Arguments.Skip();
                        }
                    }

                    if (u.Id == e.Author.Id)
                    {
                        mentionedSelf = true;
                        continue;
                    }

                    totalAmountGiven += amount;

                    if (usersMentioned.Keys.Where(x => x.Id == u.Id).Count() > 0)
                    {
                        usersMentioned[usersMentioned.Keys.Where(x => x.Id == u.Id).First()] += amount;
                    }
                    else
                    {
                        usersMentioned.Add(u, amount);
                    }
                }

                if (mentionedSelf)
                {
                    embed.Footer = new EmbedFooter()
                    {
                        Text = e.Locale.GetString("warning_mention_self"),
                    };
                }

                if (usersMentioned.Count == 0)
                {
                    return;
                }
                else
                {
                    if (totalAmountGiven <= 0)
                    {
                        await e.ErrorEmbedResource("miki_module_accounts_rep_error_zero")
                        .ToEmbed().QueueToChannelAsync(e.Channel);

                        return;
                    }

                    if (usersMentioned.Sum(x => x.Value) > repObject.ReputationPointsLeft)
                    {
                        await e.ErrorEmbedResource("error_rep_limit", usersMentioned.Count, usersMentioned.Sum(x => x.Value), repObject.ReputationPointsLeft)
                        .ToEmbed().QueueToChannelAsync(e.Channel);

                        return;
                    }
                }

                embed.Title       = (e.Locale.GetString("miki_module_accounts_rep_header"));
                embed.Description = (e.Locale.GetString("rep_success"));

                foreach (var u in usersMentioned)
                {
                    User receiver = await DatabaseHelpers.GetUserAsync(context, u.Key);

                    receiver.Reputation += u.Value;

                    embed.AddInlineField(
                        receiver.Name,
                        string.Format("{0} => {1} (+{2})", (receiver.Reputation - u.Value).ToFormattedString(), receiver.Reputation.ToFormattedString(), u.Value)
                        );
                }

                repObject.ReputationPointsLeft -= (short)usersMentioned.Sum(x => x.Value);

                await cache.UpsertAsync(
                    $"user:{giver.Id}:rep",
                    repObject,
                    DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow
                    );

                await embed.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft.ToString())
                .ToEmbed().QueueToChannelAsync(e.Channel);

                await context.SaveChangesAsync();
            }
        }
Esempio n. 16
0
        public async Task LotteryAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                long totalTickets = await(Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListLengthAsync(lotteryKey);
                long yourTickets  = 0;

                string latestWinner = (Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).StringGet("lottery:winner");

                if (await lotteryDict.ContainsAsync(e.Author.Id))
                {
                    yourTickets = long.Parse(await lotteryDict.GetAsync(e.Author.Id));
                }

                string timeLeft = taskScheduler?.GetInstance(0, lotteryId).TimeLeft.ToTimeString(e.Locale, true) ?? "1h?m?s - will be fixed soon!";

                new EmbedBuilder()
                {
                    Title       = "🍀 Lottery",
                    Description = "Make the biggest gamble, and get paid off massively if legit.",
                    Color       = new Color(119, 178, 85)
                }.AddInlineField("Tickets Owned", yourTickets.ToString())
                .AddInlineField("Drawing In", timeLeft)
                .AddInlineField("Total Tickets", totalTickets.ToString())
                .AddInlineField("Ticket price", $"{100} mekos")
                .AddInlineField("Latest Winner", latestWinner ?? "no name")
                .AddInlineField("How to buy?", ">lottery buy [amount]")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            switch (arg.Argument.ToLower())
            {
            case "buy":
            {
                arg = arg.Next();
                int amount = arg?.AsInt() ?? 1;

                if (amount < 1)
                {
                    amount = 1;
                }

                using (var context = new MikiContext())
                {
                    User u = await DatabaseHelpers.GetUserAsync(context, e.Author);

                    if (amount * 100 > u.Currency)
                    {
                        e.ErrorEmbedResource("miki_mekos_insufficient")
                        .ToEmbed().QueueToChannel(e.Channel);
                        return;
                    }

                    await u.AddCurrencyAsync(-amount * 100, e.Channel);

                    RedisValue[] tickets = new RedisValue[amount];

                    for (int i = 0; i < amount; i++)
                    {
                        tickets[i] = e.Author.Id.ToString();
                    }

                    await(Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListRightPushAsync(lotteryKey, tickets);

                    int totalTickets = 0;

                    if (await lotteryDict.ContainsAsync(e.Author.Id.ToString()))
                    {
                        totalTickets = int.Parse(await lotteryDict.GetAsync(e.Author.Id.ToString()));
                    }

                    await lotteryDict.AddAsync(e.Author.Id, amount + totalTickets);

                    await context.SaveChangesAsync();

                    e.SuccessEmbed($"Successfully bought {amount} tickets!")
                    .QueueToChannel(e.Channel);
                }
            }
            break;
            }
        }