public async Task DailyReminderLookup() { var reminders = ReminderHandler.Database.Query <PersistentReminder>(x => x.UserId == Context.User.Id); if (!reminders.Any()) { await ReplyAsync("You have no reminders."); return; } var pager = new ReactivePager(); pager.Pages = reminders.Select(x => new ReactivePage { Description = x.ReminderMessage, Title = $"Reminder: #{x.ReminderNumber} sent in {Context.Client.GetGuild(x.GuildId)?.GetTextChannel(x.ChannelId)?.Name ?? "DMs"}", FooterOverride = new Discord.EmbedFooterBuilder { Text = $"At {x.ActivationTime.ToString("hh\\:mm")} daily {GetGMTString(x.GMTAdjustment)}" } }).ToList(); await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); }
public async Task PagerTest() { var pages = new List <ReactivePage> { new ReactivePage { Description = "a" }, new ReactivePage { Description = "b" }, new ReactivePage { Description = "c" }, new ReactivePage { Description = "d" }, new ReactivePage { Description = "e" }, new ReactivePage { Description = "f" }, }; var pager = new ReactivePager(pages); await PagedReplyAsync(pager .ToCallBack() .WithDefaultPagerCallbacks() .WithCallback(new Emoji("➕"), async(callback, reaction) => { callback.AddPage(new ReactivePage { Description = callback.pages.ToString() }); await callback.RenderAsync(); return(false); }) .WithCallback(new Emoji("➖"), async(callback, reaction) => { callback.RemovePage(callback.page); await callback.RenderAsync(); return(false); }) .WithCallback(new Emoji("🔄"), async(callback, reaction) => { callback.SetPages(pages); await callback.RenderAsync(); return(false); })); }
public virtual async Task Bans() { using (var db = new Database()) { var bans = db.Bans.Where(x => x.GuildId == Context.Guild.Id).ToList(); if (bans.Count == 0) { await SimpleEmbedAsync("There aren't any banned players.", Color.Blue); return; } //Show bans in order of which is soonest to expire var pages2 = bans.Where(x => x.IsExpired == false).OrderBy(x => x.RemainingTime).SplitList(5).Select(x => { var page = new ReactivePage(); page.Fields = x.Select(p => { var user = db.Players.Find(Context.Guild.Id, p.UserId); var field = new EmbedFieldBuilder { Name = user?.GetDisplayNameSafe() ?? p.UserId.ToString(), Value = $"**User:** {MentionUtils.MentionUser(p.UserId)}\n" + $"**Banned at:** {p.ExpiryTime.ToString("dd MMM yyyy")}\n" + $"**Ban Length:** {p.Length.GetReadableLength()}\n" + $"**Expires in:** {p.RemainingTime.GetReadableLength()}\n" + $"**Banned by:** {MentionUtils.MentionUser(p.Moderator)}\n" + $"**Reason:** {p.Comment ?? "N/A"}" }; return(field); }).ToList(); return(page); }); if (!pages2.Any()) { await SimpleEmbedAsync("There are no players currently banned. Use the `Allbans` command to lookup all player bans."); return; } var pager2 = new ReactivePager(pages2); await PagedReplyAsync(pager2.ToCallBack().WithDefaultPagerCallbacks()); } }
public async Task ShowLeaderboard() { var users = LevelService.Database.Query <LevelUser>(x => x.GuildId == Context.Guild.Id).OrderByDescending(x => x.UserXP).ToList(); if (!users.Any()) { await ReplyAsync("There are no users with levelling in this server."); return; } await Context.Guild.DownloadUsersAsync(); var pages = new List <ReactivePage>(); int position = 0; foreach (var userGroup in users.SplitList(15)) { var page = new ReactivePage(); var userText = userGroup.Select(x => { var user = Context.Guild.GetUser(x.UserId); if (user == null) { return(null); } position++; return($"#{position} | {user.Mention} XP:{x.UserXP} LV:{x.UserLevel}"); }).Where(x => x != null); page.Description = string.Join("\n", userText); pages.Add(page); } var pager = new ReactivePager { Title = "Leaderboard", Pages = pages, Color = Color.Blue }; await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); }
public async Task Bans() { var players = Service.GetPlayers(x => x.GuildId == Context.Guild.Id && x.IsBanned); if (players.Length == 0) { await SimpleEmbedAsync("There aren't any banned players.", Color.Blue); return; } var pages = players.OrderBy(x => x.CurrentBan.RemainingTime).SplitList(20).Select(x => { var page = new ReactivePage(); page.Description = string.Join("\n", x.Select(p => $"{MentionUtils.MentionUser(p.UserId)} - {p.CurrentBan.ExpiryTime.ToString("dd MMM yyyy")} {p.CurrentBan.ExpiryTime.ToShortTimeString()} in {p.CurrentBan.RemainingTime.GetReadableLength()}")); return(page); }); var pager = new ReactivePager(pages); await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); }
public virtual async Task AllBans() { using (var db = new Database()) { var bans = db.Bans.Where(x => x.GuildId == Context.Guild.Id).ToList(); if (bans.Count == 0) { await SimpleEmbedAsync("There aren't any banned players.", Color.Blue); return; } var pages2 = bans.OrderBy(x => x.RemainingTime).SplitList(5).Select(x => { var page = new ReactivePage(); page.Fields = x.Select(p => { var user = db.Players.Find(Context.Guild.Id, p.UserId); var field = new EmbedFieldBuilder { Name = user?.DisplayName ?? p.UserId.ToString(), Value = $"**User:** {MentionUtils.MentionUser(p.UserId)}\n" + $"**Banned at:** {p.ExpiryTime.ToString("dd MMM yyyy")}\n" + $"**Ban Length:** {p.Length.GetReadableLength()}\n" + $"**Banned By:** {MentionUtils.MentionUser(p.Moderator)}\n" + $"**Manually Disabled:** {p.ManuallyDisabled}\n" + $"**Reason:** {p.Comment ?? "N/A"}\n" + $"**Expired:** {p.IsExpired}" }; return(field); }).ToList(); return(page); }); var pager2 = new ReactivePager(pages2); await PagedReplyAsync(pager2.ToCallBack().WithDefaultPagerCallbacks()); } }
private async Task SendModLogMessage(EmbedFieldBuilder[] fields, string header) { if (!fields.Any()) { await ReplyAsync("There are no mod log actions that match the specified search query"); return; } var pages = fields.SplitList(x => x.Name.Length + x.Value.ToString().Length, 5000).Select(x => new ReactivePage { Fields = x.ToList() }).ToList(); var pager = new ReactivePager { Pages = pages, Title = header }; await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); }
public async Task RemindersListAsync() { var reminders = ReminderHandler.Database.Query <Reminder>(x => x.UserId == Context.User.Id).ToArray(); if (reminders.Length == 0) { await ReplyAsync("There are no reminders in queue for you."); return; } var currentServer = reminders.Where(x => x.GuildId == Context.Guild.Id).ToArray(); var currentChannel = currentServer.Where(x => x.ChannelId == Context.Channel.Id).ToArray(); var pager = new ReactivePager(); var p1 = new ReactivePage { Title = "Overview", Description = $"**Total Reminders:** {reminders.Length}\n" + $"**Total Reminders in this Server:** {currentServer.Length}\n" + $"**Total Reminders in this Channel:** {currentChannel.Length}\n" }; var pages = new List <ReactivePage> { p1 }; var fields = reminders.Select(x => { var dueAt = (x.TimeStamp + x.Length); var guild = Context.Client.GetGuild(x.GuildId); var channel = guild?.GetTextChannel(x.ChannelId); return(new EmbedFieldBuilder { Name = $"Reminder: {x.ReminderNumber}", Value = $"**At:** {dueAt.ToLongDateString()} {dueAt.ToLongTimeString()}\n" + $"**Due In:** {(dueAt - DateTime.UtcNow).GetReadableLength()}\n" + $"**Server:** {guild?.Name ?? "N/A"}\n" + $"**Channel:** {channel?.Name ?? "N/A"}\n**Message:**\n" + $"{x.ReminderMessage}" }); }).SplitList(5).ToList(); if (fields.Count > 1) { p1.Fields = fields.First().ToList(); foreach (var grp in fields.Skip(1)) { pages.Add(new ReactivePage { Fields = grp.ToList() }); } } else if (fields.Count == 1) { p1.Fields = fields.First().ToList(); } pager.Pages = pages; await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); }
public async Task LyricsAsync() { if (player.CurrentTrack is null) { await ReplyAsync("There is no track playing right now."); return; } var lyrics = await Vic.ScrapeGeniusLyricsAsync(player.CurrentTrack.Title); if (lyrics == null) { await ReplyAsync("Could not fetch lyrics."); return; } var thumb = await player.CurrentTrack.FetchThumbnailAsync(); var pager = new ReactivePager(); var pages = new List <ReactivePage>(); string[] paragraphs = Regex.Split(lyrics, "(\n){2,}"); foreach (var group in paragraphs) { //Ensure that we are not including un-necessary empty pages if (string.IsNullOrWhiteSpace(group)) { continue; } //Ensure that the length of the paragraph does not exceed the max embed length if (group.Length >= 2048) { //Split the paragraph into sub-groups and add individually var words = group.Split(" "); var sb = new StringBuilder(); //Add the words of each group individually to ensure that the response is still coherent foreach (var word in words) { if (sb.Length + word.Length >= 2048) { pages.Add(new ReactivePage() { Description = sb.ToString() }); sb.Clear(); } sb.Append($"{word} "); } //Ensure that any remaining content is added to the pager. var remaining = sb.ToString(); if (!string.IsNullOrWhiteSpace(remaining)) { pages.Add(new ReactivePage() { Description = remaining }); } } else { pages.Add(new ReactivePage() { Description = group }); } } pager.Pages = pages; if (pager.Pages.Any()) { pager.Pages.First().ImageUrl = thumb; pager.Pages.First().Author = new EmbedAuthorBuilder() { Name = $"Lyrics For {player.CurrentTrack.Title}", IconUrl = thumb }; await PagedReplyAsync(pager.ToCallBack().WithDefaultPagerCallbacks()); } }