Esempio n. 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();
            }
        }
Esempio n. 2
0
        public async Task DeclineMarriageAsync(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                var marriages = await Marriage.GetProposalsReceived(context, e.Author.Id.ToDbLong());

                if (marriages.Count == 0)
                {
                    throw new Exception("You do not have any proposals.");
                }

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

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

                new EmbedBuilder()
                {
                    Title       = $"🔫 You shot down {otherName}!",
                    Description = $"Aww, don't worry {otherName}. There is plenty of fish in the sea!",
                    Color       = new Color(191, 105, 82)
                }.ToEmbed().QueueToChannel(e.Channel);

                m.Remove(context);
                await context.SaveChangesAsync();
            }
        }
Esempio n. 3
0
        public async Task <UserMarriedTo> GetEntryAsync(long receiver, long asker)
        {
            UserMarriedTo marriedTo = await(await marriedToRepository.ListAsync())
                                      .AsQueryable()
                                      .Include(x => x.Marriage)
                                      .FirstOrDefaultAsync(x => x.AskerId == asker && x.ReceiverId == receiver ||
                                                           x.AskerId == receiver && x.ReceiverId == asker);

            return(marriedTo);
        }
Esempio n. 4
0
        public async Task <UserMarriedTo> GetMarriageAsync(long receiver, long asker)
        {
            UserMarriedTo m = await InternalGetMarriageAsync(receiver, asker);

            if (m == null)
            {
                m = await InternalGetMarriageAsync(asker, receiver);
            }

            return(m);
        }
Esempio n. 5
0
        public async Task <UserMarriedTo> GetEntryAsync(long receiver, long asker)
        {
            UserMarriedTo m = null;

            m = await _userMarriedSet
                .Include(x => x.Marriage)
                .FirstOrDefaultAsync(x => (x.AskerId == asker && x.ReceiverId == receiver) ||
                                     (x.AskerId == receiver && x.ReceiverId == asker));

            return(m);
        }
Esempio n. 6
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;
                }
            }
        }
Esempio n. 7
0
        public async Task AcceptMarriageAsync(CommandContext e)
        {
            IDiscordUser user = await DiscordExtensions.GetUserAsync(e.Arguments.Pack.TakeAll(), e.Guild);

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

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

                return;
            }

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

            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.QueueMessage($"You can not accept your own responses!");
                    return;
                }

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

                    await context.SaveChangesAsync();

                    await 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().QueueToChannelAsync(e.Channel);
                }
                else
                {
                    await e.ErrorEmbed("You're already married to this person ya doofus!")
                    .ToEmbed().QueueToChannelAsync(e.Channel);
                }
            }
            else
            {
                e.Channel.QueueMessage("This user hasn't proposed to you!");
                return;
            }
        }
Esempio n. 8
0
        public async ValueTask DeclineProposalAsync(UserMarriedTo userMarriedTo)
        {
            await marriedToRepository.DeleteAsync(userMarriedTo);

            await unitOfWork.CommitAsync();
        }
Esempio n. 9
0
        public async Task AcceptMarriageAsync(IContext e)
        {
            var userService = e.GetService <IUserService>();

            IDiscordUser user = await e.GetGuild().FindUserAsync(e);

            if (user.Id == e.GetAuthor().Id)
            {
                await e.ErrorEmbed("Please mention someone else than yourself.")
                .ToEmbed()
                .QueueAsync(e, e.GetChannel())
                .ConfigureAwait(false);

                return;
            }

            var service = e.GetService <MarriageService>();

            User accepter = await userService.GetOrCreateUserAsync(e.GetAuthor())
                            .ConfigureAwait(false);

            User asker = await userService.GetOrCreateUserAsync(user)
                         .ConfigureAwait(false);

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

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

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

                if (marriage.ReceiverId != (long)e.GetAuthor().Id)
                {
                    e.GetChannel().QueueMessage(e, null, $"You can not accept your own responses!");
                    return;
                }

                if (marriage.Marriage.IsProposing)
                {
                    await service.AcceptProposalAsync(marriage.Marriage);

                    await new EmbedBuilder
                    {
                        Title       = ("❤️ Happily married"),
                        Color       = new Color(190, 25, 49),
                        Description = ($"Much love to { e.GetAuthor().Username } and { user.Username } in their future adventures together!")
                    }.ToEmbed().QueueAsync(e, e.GetChannel())
                    .ConfigureAwait(false);
                }
                else
                {
                    await e.ErrorEmbed("You're already married to this person. you doofus!")
                    .ToEmbed()
                    .QueueAsync(e, e.GetChannel())
                    .ConfigureAwait(false);
                }
            }
            else
            {
                await e.ErrorEmbed("This user hasn't proposed to you!")
                .ToEmbed()
                .QueueAsync(e, e.GetChannel())
                .ConfigureAwait(false);
            }
        }