public async Task DeclineMarriageAsync(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.GetProposalsReceived(e.Author.Id.ToDbLong()); if (marriages.Count == 0) { // TODO: add no propsoals //throw new LocalizedException("error_proposals_empty"); return; } marriages = marriages.OrderByDescending(x => x.Marriage.TimeOfMarriage).ToList(); if (selectionId != null) { var m = marriages[selectionId.Value - 1]; string otherName = (await Global.Client.Discord.GetUserAsync(m.GetOther(e.Author.Id.ToDbLong()).FromDbLong())).Username; 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(); } else { var embed = new EmbedBuilder() { Title = "💍 Proposals", Footer = new EmbedFooter() { Text = $"Use {await e.Prefix.GetForGuildAsync(Global.RedisClient, e.Guild.Id)}declinemarriage <number> to decline", }, Color = new Color(154, 170, 180) }; await BuildMarriageEmbedAsync(embed, e.Author.Id.ToDbLong(), context, marriages); embed.ToEmbed().QueueToChannel(e.Channel); } } }
public async Task DeclineMarriageAsync(EventContext e) { using (MikiContext context = new MikiContext()) { MarriageRepository repository = new MarriageRepository(context); var marriages = await repository.GetProposalsReceived(e.Author.Id.ToDbLong()); if (marriages.Count == 0) { // TODO: add no propsoals //throw new LocalizedException("error_proposals_empty"); return; } marriages = marriages.OrderByDescending(x => x.Marriage.TimeOfMarriage).ToList(); if (e.Arguments.Take(out int selectionId)) { var m = marriages[selectionId - 1]; string otherName = (await MikiApp.Instance.Discord.GetUserAsync(m.GetOther(e.Author.Id.ToDbLong()).FromDbLong())).Username; await 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().QueueToChannelAsync(e.Channel); m.Remove(context); await context.SaveChangesAsync(); } else { var cache = (ICacheClient)e.Services.GetService(typeof(ICacheClient)); var embed = new EmbedBuilder() { Title = "💍 Proposals", Footer = new EmbedFooter() { Text = $"Use {await e.Prefix.GetForGuildAsync(context, cache, e.Guild.Id)}declinemarriage <number> to decline", }, Color = new Color(154, 170, 180) }; await BuildMarriageEmbedAsync(embed, e.Author.Id.ToDbLong(), context, marriages); await embed.ToEmbed().QueueToChannelAsync(e.Channel); } } }
public async Task ShowProposalsAsync(EventContext e) { int page = e.Arguments.FirstOrDefault()?.TakeInt() - 1 ?? 0; using (var context = new MikiContext()) { MarriageRepository repository = new MarriageRepository(context); List <UserMarriedTo> proposals = await repository.GetProposalsReceived(e.Author.Id.ToDbLong()); List <string> proposalNames = new List <string>(); foreach (UserMarriedTo p in proposals) { long id = p.GetOther(e.Author.Id.ToDbLong()); string u = (await Global.Client.Discord.GetUserAsync(id.FromDbLong())).Username; proposalNames.Add($"{u} [{id}]"); } int pageCount = (int)Math.Ceiling((float)proposalNames.Count / 35); proposalNames = proposalNames.Skip(page * 35) .Take(35) .ToList(); EmbedBuilder embed = new EmbedBuilder() .SetTitle(e.Author.Username) .SetDescription("Here it shows both the people who you've proposed to and who have proposed to you."); string output = string.Join("\n", proposalNames); embed.AddField("Proposals Recieved", string.IsNullOrEmpty(output) ? "none (yet!)" : output); proposals = await repository.GetProposalsSent(e.Author.Id.ToDbLong()); proposalNames = new List <string>(); foreach (UserMarriedTo p in proposals) { long id = p.GetOther(e.Author.Id.ToDbLong()); string u = (await Global.Client.Discord.GetUserAsync(id.FromDbLong())).Username; proposalNames.Add($"{u} [{id}]"); } pageCount = Math.Max(pageCount, (int)Math.Ceiling((float)proposalNames.Count / 35)); proposalNames = proposalNames.Skip(page * 35) .Take(35) .ToList(); output = string.Join("\n", proposalNames); embed.AddField("Proposals Sent", string.IsNullOrEmpty(output) ? "none (yet!)" : output); embed.Color = new Color(1, 0.5f, 0); embed.ThumbnailUrl = (await e.Guild.GetMemberAsync(e.Author.Id)).GetAvatarUrl(); if (pageCount > 1) { embed.SetFooter(e.Locale.GetString("page_footer", page + 1, pageCount)); } embed.ToEmbed().QueueToChannel(e.Channel); } }