Beispiel #1
0
        public async Task CancelMarriageAsync(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                var marriages = await repository.GetProposalsSent(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 took back your proposal to {otherName}!",
                        Description = $"Aww, don't worry {otherName}. There is plenty of fish in the sea!",
                        Color       = new Color(231, 90, 112)
                    }.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)}cancelmarriage <number> to decline",
                        },
                        Color = new Color(154, 170, 180)
                    };

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

                    await embed.ToEmbed()
                    .QueueToChannelAsync(e.Channel);
                }
            }
        }
Beispiel #2
0
        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);
            }
        }