示例#1
0
        public async Task DivorceAsync(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong());

            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)
                    {
                        await Utils.ErrorEmbed(locale, locale.GetString("miki_module_accounts_error_no_marriage")).SendToChannel(e.Channel);
                    }
                    else if (users.Count == 1)
                    {
                        Marriage currentMarriage = Marriage.GetMarriage(context, e.Author.Id, users.First().Id.FromDbLong());
                        if (currentMarriage == null)
                        {
                            await Utils.ErrorEmbed(locale, locale.GetString("miki_module_accounts_error_no_marriage")).SendToChannel(e.Channel);

                            return;
                        }

                        if (currentMarriage.Proposing)
                        {
                            await Utils.ErrorEmbed(locale, locale.GetString("miki_module_accounts_error_no_marriage")).SendToChannel(e.Channel);

                            return;
                        }

                        await currentMarriage.DivorceAsync(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 IA.SDK.Color(0.6f, 0.4f, 0.1f);
                        await embed.SendToChannel(e.Channel);

                        return;
                    }
                    else
                    {
                        List <Marriage> allMarriages = Marriage.GetMarriages(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.DivorceAsync(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 IA.SDK.Color(0.6f, 0.4f, 0.1f);
                                    await embed.SendToChannel(e.Channel);

                                    break;
                                }
                            }

                            if (done)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                if (e.Author.Id == e.message.MentionedUserIds.First())
                {
                    await Utils.ErrorEmbed(locale, locale.GetString("miki_module_accounts_error_no_marriage")).SendToChannel(e.Channel);

                    return;
                }

                using (MikiContext context = new MikiContext())
                {
                    Marriage currentMarriage = Marriage.GetMarriage(context, e.Author.Id, e.message.MentionedUserIds.First());

                    await currentMarriage.DivorceAsync(context);

                    string user1 = (await e.Guild.GetUserAsync(currentMarriage.GetMe(e.Author.Id))).Username;
                    string user2 = (await e.Guild.GetUserAsync(currentMarriage.GetOther(e.Author.Id))).Username;

                    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 IA.SDK.Color(0.6f, 0.4f, 0.1f);
                    await embed.SendToChannel(e.Channel);
                }
            }
        }
示例#2
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);
                    }
                }
            }
        }