public async Task AcceptMarriageAsync(EventContext e) { if (e.message.MentionedUserIds.Count == 0) { await e.Channel.SendMessage("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.Id1); User person2 = await context.Users.FindAsync(marriage.Id2); if (person1.MarriageSlots < Marriage.GetMarriages(context, person1.Id).Count) { await e.Channel.SendMessage($"{person1.Name} do not have enough marriage slots, sorry :("); return; } if (person2.MarriageSlots < Marriage.GetMarriages(context, person2.Id).Count) { await e.Channel.SendMessage($"{person2.Name} does not have enough marriage slots, sorry :("); return; } marriage.AcceptProposal(context); Log.Message(marriage.Proposing.ToString()); await context.SaveChangesAsync(); await e.Channel.SendMessage($"❤️ Congratulations { person1.Name } and { person2.Name } ❤️"); } else { await e.Channel.SendMessage("This user hasn't proposed to you!"); return; } } }
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; } } }