예제 #1
0
        public async Task DivorceAsync(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                var marriages = await Marriage.GetMarriagesAsync(context, e.Author.Id.ToDbLong());

                if (marriages.Count == 0)
                {
                    throw new Exception("You're not married to anyone.");
                }

                UserMarriedTo m = await SelectMarriageAsync(e, context, marriages);

                string otherName = await User.GetNameAsync(context, m.GetOther(e.Author.Id.ToDbLong()));

                EmbedBuilder embed = Utils.Embed;
                embed.Title       = $"🔔 {e.GetResource("miki_module_accounts_divorce_header")}";
                embed.Description = e.GetResource("miki_module_accounts_divorce_content", e.Author.Username, otherName);
                embed.Color       = new Color(0.6f, 0.4f, 0.1f);
                embed.ToEmbed().QueueToChannel(e.Channel);

                m.Remove(context);
                await context.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task AcceptMarriageAsync(EventContext e)
        {
            if (e.message.MentionedUserIds.Count == 0)
            {
                await e.Channel.QueueMessageAsync("Please mention the person you want to marry.");

                return;
            }

            using (var context = new MikiContext())
            {
                Marriage marriage = await Marriage.GetProposalReceivedAsync(context, e.message.MentionedUserIds.First(), e.Author.Id);

                if (marriage != null)
                {
                    User person1 = await context.Users.FindAsync(marriage.Participants.FirstOrDefault(x => x.Asker).UserId);

                    User person2 = await context.Users.FindAsync(marriage.Participants.FirstOrDefault(x => !x.Asker).UserId);

                    if (person1.MarriageSlots < (await Marriage.GetMarriagesAsync(context, person1.Id)).Count)
                    {
                        await e.Channel.QueueMessageAsync($"{person1.Name} do not have enough marriage slots, sorry :(");

                        return;
                    }

                    if (person2.MarriageSlots < (await Marriage.GetMarriagesAsync(context, person2.Id)).Count)
                    {
                        await e.Channel.QueueMessageAsync($"{person2.Name} does not have enough marriage slots, sorry :(");

                        return;
                    }

                    marriage.AcceptProposal(context);

                    await context.SaveChangesAsync();

                    await e.Channel.QueueMessageAsync($"❤️ Congratulations { person1.Name } and { person2.Name } ❤️");
                }
                else
                {
                    await e.Channel.QueueMessageAsync("This user hasn't proposed to you!");

                    return;
                }
            }
        }
예제 #3
0
        public async Task ProfileAsync(EventContext e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (var context = new MikiContext())
            {
                long  id  = 0;
                ulong uid = 0;

                var arg = e.Arguments.FirstOrDefault();

                if (arg != null)
                {
                    uid = (await arg.GetUserAsync(e.Guild)).Id;
                    id  = uid.ToDbLong();
                }
                else
                {
                    uid = e.message.Author.Id;
                    id  = uid.ToDbLong();
                }

                IDiscordGuildUser discordUser = await e.Guild.GetUserAsync(uid);

                User account = await User.GetAsync(context, discordUser);

                string icon = "";

                if (await account.IsDonatorAsync(context))
                {
                    icon = "https://cdn.discordapp.com/emojis/421969679561785354.png";
                }

                if (account != null)
                {
                    EmbedBuilder embed = Utils.Embed
                                         .SetDescription(account.Title)
                                         .SetAuthor(e.GetResource("miki_global_profile_user_header", account.Name), icon, "https://patreon.com/mikibot")
                                         .SetThumbnail(discordUser.GetAvatarUrl());

                    long serverid = e.Guild.Id.ToDbLong();

                    LocalExperience localExp = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), discordUser);

                    if (localExp == null)
                    {
                        localExp = await LocalExperience.CreateAsync(context, serverid, discordUser);
                    }

                    int rank = await localExp.GetRank(context);

                    int localLevel  = User.CalculateLevel(localExp.Experience);
                    int maxLocalExp = User.CalculateLevelExperience(localLevel);
                    int minLocalExp = User.CalculateLevelExperience(localLevel - 1);

                    EmojiBar expBar = new EmojiBar(maxLocalExp - minLocalExp, onBarSet, offBarSet, 6);

                    string infoValue = new MessageBuilder()
                                       .AppendText(e.GetResource("miki_module_accounts_information_level", localLevel, localExp.Experience, maxLocalExp))
                                       .AppendText(await expBar.Print(localExp.Experience - minLocalExp, (IDiscordGuildChannel)e.Channel))
                                       .AppendText(e.GetResource("miki_module_accounts_information_rank", rank))
                                       .AppendText("Reputation: " + account.Reputation, MessageFormatting.Plain, false)
                                       .Build();

                    embed.AddInlineField(e.GetResource("miki_generic_information"), infoValue);

                    int globalLevel  = User.CalculateLevel(account.Total_Experience);
                    int maxGlobalExp = User.CalculateLevelExperience(globalLevel);
                    int minGlobalExp = User.CalculateLevelExperience(globalLevel - 1);

                    int globalRank = await account.GetGlobalRankAsync();

                    EmojiBar globalExpBar = new EmojiBar(maxGlobalExp - minGlobalExp, onBarSet, offBarSet, 6);

                    string globalInfoValue = new MessageBuilder()
                                             .AppendText(e.GetResource("miki_module_accounts_information_level", globalLevel, account.Total_Experience, maxGlobalExp))
                                             .AppendText(
                        await globalExpBar.Print(account.Total_Experience - minGlobalExp, e.Channel as IDiscordGuildChannel)
                        )
                                             .AppendText(e.GetResource("miki_module_accounts_information_rank", globalRank), MessageFormatting.Plain, false)
                                             .Build();

                    embed.AddInlineField(e.GetResource("miki_generic_global_information"), globalInfoValue);
                    embed.AddInlineField(e.GetResource("miki_generic_mekos"), account.Currency + "<:mekos:421972155484471296>");

                    List <UserMarriedTo> Marriages = await Marriage.GetMarriagesAsync(context, id);

                    Marriages.RemoveAll(x => x.Marriage.IsProposing);

                    List <string> users = new List <string>();

                    int maxCount = Marriages?.Count ?? 0;

                    for (int i = 0; i < maxCount; i++)
                    {
                        users.Add(await User.GetNameAsync(context, Marriages[i].GetOther(id)));
                    }

                    if (Marriages?.Count > 0)
                    {
                        List <string> MarriageStrings = new List <string>();

                        for (int i = 0; i < maxCount; i++)
                        {
                            if (Marriages[i].GetOther(id) != 0)
                            {
                                MarriageStrings.Add($"💕 {users[i]} (_{Marriages[i].Marriage.TimeOfMarriage.ToShortDateString()}_)");
                            }
                        }

                        string marriageText = string.Join("\n", MarriageStrings);
                        if (string.IsNullOrEmpty(marriageText))
                        {
                            marriageText = e.GetResource("miki_placeholder_null");
                        }

                        embed.AddInlineField(
                            e.GetResource("miki_module_accounts_profile_marriedto"),
                            marriageText);
                    }

                    Random r = new Random((int)id - 3);
                    Color  c = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());

                    embed.SetColor(c);

                    CommandUsage favouriteCommand = await context.CommandUsages
                                                    .OrderByDescending(x => x.Amount)
                                                    .FirstOrDefaultAsync(x => x.UserId == id);

                    string favCommand = $"{favouriteCommand?.Name ?? e.GetResource("miki_placeholder_null")} ({ favouriteCommand?.Amount ?? 0 })";

                    embed.AddInlineField(e.GetResource("miki_module_accounts_profile_favourite_command"),
                                         favCommand);

                    List <Achievement> allAchievements = await context.Achievements.Where(x => x.Id == id).ToListAsync();

                    string achievements = e.GetResource("miki_placeholder_null");

                    if (allAchievements != null)
                    {
                        if (allAchievements.Count > 0)
                        {
                            achievements = AchievementManager.Instance.PrintAchievements(allAchievements);
                        }
                    }

                    embed.AddInlineField(
                        e.GetResource("miki_generic_achievements"),
                        achievements);

                    embed.SetFooter(
                        e.GetResource("miki_module_accounts_profile_footer", account.DateCreated.ToShortDateString(),
                                      sw.ElapsedMilliseconds), "");

                    sw.Stop();

                    embed.ToEmbed().QueueToChannel(e.Channel);
                }
                else
                {
                    e.ErrorEmbed(e.GetResource("error_account_null"))
                    .ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }
예제 #4
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);
            }

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

            using (var context = new MikiContext())
            {
                User accepter = await User.GetAsync(context, e.Author);

                User asker = await User.GetAsync(context, user);

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

                if (marriage != null)
                {
                    if (accepter.MarriageSlots < (await Marriage.GetMarriagesAsync(context, accepter.Id)).Count)
                    {
                        e.Channel.QueueMessageAsync($"{e.Author.Username} do not have enough Marriage slots, sorry :(");
                        return;
                    }

                    if (asker.MarriageSlots < (await Marriage.GetMarriagesAsync(context, asker.Id)).Count)
                    {
                        e.Channel.QueueMessageAsync($"{asker.Name} does not have enough Marriage slots, sorry :(");
                        return;
                    }

                    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(context);

                        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;
                }
            }
        }
예제 #5
0
        public async Task AcceptMarriageAsync(EventContext e)
        {
            if (e.message.MentionedUserIds.Count == 0)
            {
                e.ErrorEmbed("Please mention the person you want to marry.")
                .QueueToChannel(e.Channel);
                return;
            }

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

            using (var context = new MikiContext())
            {
                User accepter = await User.GetAsync(context, e.Author);

                IDiscordUser user = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First());

                User asker = await User.GetAsync(context, user);

                Marriage Marriage = accepter.Marriages
                                    .FirstOrDefault(x => asker.Marriages
                                                    .Any(z => z.MarriageId == x.MarriageId)).Marriage;

                if (Marriage != null)
                {
                    if (accepter.MarriageSlots < (await Marriage.GetMarriagesAsync(context, accepter.Id)).Count)
                    {
                        e.Channel.QueueMessageAsync($"{e.Author.GetName()} do not have enough Marriage slots, sorry :(");
                        return;
                    }

                    if (asker.MarriageSlots < (await Marriage.GetMarriagesAsync(context, asker.Id)).Count)
                    {
                        e.Channel.QueueMessageAsync($"{asker.Name} does not have enough Marriage slots, sorry :(");
                        return;
                    }

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

                        await context.SaveChangesAsync();

                        Utils.Embed
                        .SetTitle("❤️ Happily married")
                        .SetColor(190, 25, 49)
                        .SetDescription($"Much love to { e.Author.GetName() } and { user.GetName() } in their future adventures together!")
                        .QueueToChannel(e.Channel);
                    }
                    else
                    {
                        e.ErrorEmbed("You're already married to this person ya doofus!")
                        .QueueToChannel(e.Channel);
                    }
                }
                else
                {
                    e.Channel.QueueMessageAsync("This user hasn't proposed to you!");
                    return;
                }
            }
        }
예제 #6
0
        public async Task DivorceAsync(EventContext e)
        {
            Locale locale = new Locale(e.Channel.Id);

            if (e.message.MentionedUserIds.Count == 0)
            {
                using (MikiContext context = new MikiContext())
                {
                    List <User> users = context.Users.Where(p => p.Name.ToLower() == e.arguments.ToLower()).ToList();

                    if (users.Count == 0)
                    {
                        e.ErrorEmbed(locale.GetString("miki_module_accounts_error_no_Marriage"))
                        .QueueToChannel(e.Channel);
                    }
                    else if (users.Count == 1)
                    {
                        Marriage currentMarriage = await Marriage.GetMarriageAsync(context, e.Author.Id, users.First().Id.FromDbLong());

                        if (currentMarriage == null)
                        {
                            e.ErrorEmbed(locale.GetString("miki_module_accounts_error_no_Marriage"))
                            .QueueToChannel(e.Channel);
                            return;
                        }

                        if (currentMarriage.IsProposing)
                        {
                            e.ErrorEmbed(locale.GetString("miki_module_accounts_error_no_Marriage"))
                            .QueueToChannel(e.Channel);
                            return;
                        }

                        await currentMarriage.RemoveAsync(context);

                        IDiscordEmbed embed = Utils.Embed;
                        embed.Title       = locale.GetString("miki_module_accounts_divorce_header");
                        embed.Description = locale.GetString("miki_module_accounts_divorce_content", e.Author.Username, users.First().Name);
                        embed.Color       = new Common.Color(0.6f, 0.4f, 0.1f);
                        embed.QueueToChannel(e.Channel);
                        return;
                    }
                    else
                    {
                        List <Marriage> allMarriages = await Marriage.GetMarriagesAsync(context, e.Author.Id.ToDbLong());

                        bool done = false;

                        foreach (Marriage Marriage in allMarriages)
                        {
                            foreach (User user in users)
                            {
                                if (Marriage.GetOther(e.Author.Id) == user.Id.FromDbLong())
                                {
                                    await Marriage.RemoveAsync(context);

                                    done = true;

                                    IDiscordEmbed embed = Utils.Embed;
                                    embed.Title       = locale.GetString("miki_module_accounts_divorce_header");
                                    embed.Description = locale.GetString("miki_module_accounts_divorce_content", e.Author.Username, user.Name);
                                    embed.Color       = new Common.Color(0.6f, 0.4f, 0.1f);
                                    embed.QueueToChannel(e.Channel);
                                    break;
                                }
                            }

                            if (done)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                if (e.Author.Id == e.message.MentionedUserIds.First())
                {
                    e.ErrorEmbed(locale.GetString("miki_module_accounts_error_no_Marriage"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                using (MikiContext context = new MikiContext())
                {
                    User author = await User.GetAsync(context, e.Author);

                    Marriage Marriage = author.Marriages
                                        .FirstOrDefault(x => x.Marriage.GetOther(author.Id) == e.message.MentionedUserIds.First().ToDbLong())?.Marriage;

                    if (Marriage != null)
                    {
                        string user1 = (await e.Guild.GetUserAsync(Marriage.GetMe(e.Author.Id))).Username;
                        string user2 = (await e.Guild.GetUserAsync(Marriage.GetOther(e.Author.Id))).Username;

                        await Marriage.RemoveAsync(context);

                        IDiscordEmbed embed = Utils.Embed;
                        embed.Title       = locale.GetString("miki_module_accounts_divorce_header");
                        embed.Description = locale.GetString("miki_module_accounts_divorce_content", user1, user2);
                        embed.Color       = new Miki.Common.Color(0.6f, 0.4f, 0.1f);
                        embed.QueueToChannel(e.Channel);
                    }
                }
            }
        }