예제 #1
0
        public async Task DivorceAsync(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                ArgObject selection   = e.Arguments.FirstOrDefault();
                int?      selectionId = null;

                if (selection != null)
                {
                    selectionId = selection.TakeInt();
                }

                var marriages = await repository.GetMarriagesAsync((long)e.Author.Id);

                if (marriages.Count == 0)
                {
                    // TODO: no proposals exception
                    //throw BotException.CreateCustom("error_proposals_empty");
                    return;
                }

                marriages = marriages.OrderByDescending(x => x.Marriage.TimeOfMarriage).ToList();

                if (selectionId != null)
                {
                    var m         = marriages[selectionId.Value - 1];
                    var otherUser = await Global.Client.Discord.GetUserAsync(m.GetOther(e.Author.Id.ToDbLong()).FromDbLong());

                    new EmbedBuilder
                    {
                        Title       = $"🔔 {e.Locale.GetString("miki_module_accounts_divorce_header")}",
                        Description = e.Locale.GetString("miki_module_accounts_divorce_content", e.Author.Username, otherUser.Username),
                        Color       = new Color(0.6f, 0.4f, 0.1f)
                    }.ToEmbed().QueueToChannel(e.Channel);

                    m.Remove(context);
                    await context.SaveChangesAsync();
                }
                else
                {
                    var embed = new EmbedBuilder()
                    {
                        Title  = "💍 Marriages",
                        Footer = new EmbedFooter()
                        {
                            Text = $"Use {await e.Prefix.GetForGuildAsync(Global.RedisClient, e.Guild.Id)}divorce <number> to decline",
                        },
                        Color = new Color(154, 170, 180)
                    };

                    await BuildMarriageEmbedAsync(embed, e.Author.Id.ToDbLong(), context, marriages);

                    embed.ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }
예제 #2
0
        public async Task DivorceAsync(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                var marriages = await repository.GetMarriagesAsync((long)e.Author.Id);

                if (marriages.Count == 0)
                {
                    // TODO: no proposals exception
                    return;
                }

                marriages = marriages.OrderByDescending(x => x.Marriage.TimeOfMarriage).ToList();

                if (e.Arguments.Take(out int selectionId))
                {
                    var m         = marriages[selectionId - 1];
                    var otherUser = await MikiApp.Instance.Discord.GetUserAsync(m.GetOther(e.Author.Id.ToDbLong()).FromDbLong());

                    await new EmbedBuilder
                    {
                        Title       = $"🔔 {e.Locale.GetString("miki_module_accounts_divorce_header")}",
                        Description = e.Locale.GetString("miki_module_accounts_divorce_content", e.Author.Username, otherUser.Username),
                        Color       = new Color(0.6f, 0.4f, 0.1f)
                    }.ToEmbed().QueueToChannelAsync(e.Channel);

                    m.Remove(context);
                    await context.SaveChangesAsync();
                }
                else
                {
                    var cache = (ICacheClient)e.Services.GetService(typeof(ICacheClient));

                    var embed = new EmbedBuilder()
                    {
                        Title  = "💍 Marriages",
                        Footer = new EmbedFooter()
                        {
                            Text = $"Use {await e.Prefix.GetForGuildAsync(context, cache, e.Guild.Id)}divorce <number> to decline",
                        },
                        Color = new Color(154, 170, 180)
                    };

                    await BuildMarriageEmbedAsync(embed, e.Author.Id.ToDbLong(), context, marriages);

                    await embed.ToEmbed().QueueToChannelAsync(e.Channel);
                }
            }
        }
예제 #3
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;
                }
            }
        }
예제 #4
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();
                IDiscordGuildUser discordUser = null;

                MarriageRepository repository = new MarriageRepository(context);

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

                    if (discordUser == null)
                    {
                        // TODO: usernullexception
                        //throw new UserException(new User());
                    }

                    uid = discordUser.Id;
                    id  = uid.ToDbLong();
                }
                else
                {
                    uid         = e.message.Author.Id;
                    discordUser = await e.Guild.GetMemberAsync(uid);

                    id = uid.ToDbLong();
                }

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

                string icon = "";

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

                if (account != null)
                {
                    EmbedBuilder embed = new EmbedBuilder()
                                         .SetDescription(account.Title)
                                         .SetAuthor(e.Locale.GetString("miki_global_profile_user_header", discordUser.Username), icon, "https://patreon.com/mikibot")
                                         .SetThumbnail(discordUser.GetAvatarUrl());

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

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

                    int rank = await localExp.GetRankAsync(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.Locale.GetString("miki_module_accounts_information_level", localLevel, localExp.Experience.ToFormattedString(), maxLocalExp.ToFormattedString()))
                                       .AppendText(await expBar.Print(localExp.Experience - minLocalExp, e.Guild, (IDiscordGuildChannel)e.Channel))
                                       .AppendText(e.Locale.GetString("miki_module_accounts_information_rank", rank.ToFormattedString()))
                                       .AppendText("Reputation: " + account.Reputation.ToFormattedString(), MessageFormatting.Plain, false)
                                       .Build();

                    embed.AddInlineField(e.Locale.GetString("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(context);

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

                    string globalInfoValue = new MessageBuilder()
                                             .AppendText(e.Locale.GetString("miki_module_accounts_information_level", globalLevel.ToFormattedString(), account.Total_Experience.ToFormattedString(), maxGlobalExp.ToFormattedString()))
                                             .AppendText(
                        await globalExpBar.Print(account.Total_Experience - minGlobalExp, e.Guild, e.Channel as IDiscordGuildChannel)
                        )
                                             .AppendText(e.Locale.GetString("miki_module_accounts_information_rank", globalRank?.ToFormattedString() ?? "We haven't calculated your rank yet!"), MessageFormatting.Plain, false)
                                             .Build();

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

                    List <UserMarriedTo> Marriages = await repository.GetMarriagesAsync(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 Global.Client.Discord.GetUserAsync(Marriages[i].GetOther(id).FromDbLong())).Username);
                    }

                    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.Locale.GetString("miki_placeholder_null");
                        }

                        embed.AddInlineField(
                            e.Locale.GetString("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);

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

                    string achievements = e.Locale.GetString("miki_placeholder_null");

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

                    embed.AddInlineField(
                        e.Locale.GetString("miki_generic_achievements"),
                        achievements);

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

                    sw.Stop();

                    embed.ToEmbed().QueueToChannel(e.Channel);
                }
                else
                {
                    e.ErrorEmbed(e.Locale.GetString("error_account_null"))
                    .ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }