public async Task Paginator() { await _interactive.SendPaginatedMessageAsync(Context, new PaginatedMessage { Pages = new [] { "W", "u", "m", "p", "u", "s" } }); }
public async Task <CommandResult> HistoryAsync(SocketGuildUser u, bool onlyActive = false, [IsntActionType(ActionType.None)] ActionType type = default) { try { var dbGuild = await _databaseService.GetOrCreateGuildAsync(Context.Guild); var history = type == default ? dbGuild.Cases.Where(x => x.TargetId == u.Id) : dbGuild.Cases.Where(x => x.TargetId == u.Id && x.ActionType == type); history = onlyActive ? history.Where(x => !x.Resolved) : history; Console.WriteLine("aaa"); if (!history.Any()) { return(new QuiccbanFailResult(string.Format(_responseService.Get("history_no_cases"), u.ToString(), u.Mention, onlyActive ? "active " : ""))); } Console.WriteLine("bbb"); List <Embed> embeds = new List <Embed>(); var historyGrouping = history.OrderByDescending(x => x.Id).Select((@case, index) => new { Case = @case, Index = index }).GroupBy(x => x.Index / 5, x => x.Case); foreach (var group in historyGrouping) { embeds.Add(await _helperService.ConstructHistoryEmbedAsync(group, u)); } if (embeds.Count > 1) { var paginatedMessage = new PaginatedMessage { Pages = embeds }; var criterion = new Criteria <SocketReaction>(); criterion.AddCriterion(new EnsureReactionFromSourceUserCriterion()); await _interactiveService.SendPaginatedMessageAsync(Context, paginatedMessage, criterion); } else { await ReplyAsync(embed : embeds.FirstOrDefault()); } return(new QuiccbanSuccessResult()); } catch (Exception e) { Console.WriteLine(e); return(new QuiccbanSuccessResult()); } }
public async Task PaginatedMessageAsync(NixCommandContext context, List <string> pages, string title = null) { PaginatedMessage pager = new() { Title = title, Pages = pages, Color = NormalColor, Options = new() { JumpDisplayOptions = JumpDisplayOptions.Never, DisplayInformationIcon = false } }; await interactive.SendPaginatedMessageAsync(context, pager); }
public async Task ListSars(SocketCommandContext context) { using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); int roleCount = guildDb.SelfAssignableRoles.Count; if (roleCount == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Guild has no self-assignable roles!")); return; } if (roleCount < 24) { var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Title = $"Self-Assignable roles in {context.Guild.Name}", ThumbnailUrl = context.Guild.IconUrl ?? Utility.StandardDiscordAvatar, Footer = Utility.RequestedBy(context.User) }; List <Role> roleList = new List <Role>(guildDb.SelfAssignableRoles); foreach (var role in roleList) { //check if role still exists otherwise remove it var roleInfo = context.Guild.GetRole(role.RoleId); if (roleInfo == null) { guildDb.SelfAssignableRoles.Remove(role); continue; } eb.AddField(x => { x.IsInline = true; x.Name = roleInfo.Name; x.Value = $"Cost: {role.Cost}{(role.CanExpire ? $"\nDuration: {role.Duration.Humanize(2, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second, countEmptyUnits:true)}" : "")}"; }); //eb.Description += $"• {roleInfo.Name}\n"; } await context.Channel.SendMessageAsync("", embed : eb); } else { List <Role> roleList = new List <Role>(guildDb.SelfAssignableRoles); List <string> sars = new List <string>(); int pageAmount = (int)Math.Ceiling(roleCount / 7.0); int addToJ = 0; int amountLeft = roleCount; for (int i = 0; i < pageAmount; i++) { string addToList = ""; for (int j = 0; j < (amountLeft > 7 ? 7 : amountLeft); j++) { var role = roleList[j + addToJ]; var roleInfo = context.Guild.GetRole(role.RoleId); if (roleInfo == null) { guildDb.SelfAssignableRoles.Remove(role); continue; } addToList += $"**{roleInfo.Name}**\nCost: {role.Cost}{(role.CanExpire ? $" \t \tDuration: {role.Duration.Humanize(2, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second, countEmptyUnits:true)} days" : "")}"; } sars.Add(addToList); amountLeft -= 7; addToJ += 7; } var pmsg = new PaginatedMessage() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = $"Self-Assignable roles in {context.Guild.Name}", Options = new PaginatedAppearanceOptions() { DisplayInformationIcon = false, Timeout = TimeSpan.FromSeconds(60), InfoTimeout = TimeSpan.FromSeconds(60) }, Content = "Only the invoker may switch pages, ⏹ to stop the pagination", Pages = sars }; Criteria <SocketReaction> criteria = new Criteria <SocketReaction>(); criteria.AddCriterion(new EnsureReactionFromSourceUserCriterionMod()); await _interactive.SendPaginatedMessageAsync(context, pmsg, criteria); } await soraContext.SaveChangesAsync(); } }
private async Task PaginateResult(SocketCommandContext context, string title, List <ShareCentral> orderedList) { List <string> playlistsString = new List <string>(); int pageAmount = (int)Math.Ceiling(orderedList.Count / 7.0); int addToJ = 0; int amountLeft = orderedList.Count; for (int i = 0; i < pageAmount; i++) { string addToList = ""; for (int j = 0; j < (amountLeft > 7 ? 7 : amountLeft); j++) { var sharedPlaylist = orderedList[j + addToJ]; addToList += $"{(sharedPlaylist.IsPrivate ? "[P] " : "")}**[{sharedPlaylist.Titel}]({sharedPlaylist.ShareLink})**\nVotes: {sharedPlaylist.Upvotes} / {sharedPlaylist.Downvotes} \tTags: {sharedPlaylist.Tags.Replace(";", " - ")}\n\n"; } playlistsString.Add(addToList); amountLeft -= 7; addToJ += 7; } if (pageAmount > 1) { var pmsg = new PaginatedMessage() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = title, Options = new PaginatedAppearanceOptions() { DisplayInformationIcon = false, Timeout = TimeSpan.FromSeconds(60), InfoTimeout = TimeSpan.FromSeconds(60) }, Content = "Only the invoker may switch pages, ⏹ to stop the pagination", Pages = playlistsString }; Criteria <SocketReaction> criteria = new Criteria <SocketReaction>(); criteria.AddCriterion(new EnsureReactionFromSourceUserCriterionMod()); await _interactive.SendPaginatedMessageAsync(context, pmsg, criteria); } else { var eb = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = title, Description = playlistsString[0], Footer = new EmbedFooterBuilder() { Text = "Page 1/1" } }; await context.Channel.SendMessageAsync("", embed : eb); } }