public async Task <IResult> ListPermissionsAsync() { var availablePermissions = _permissionRegistry.RegisteredPermissions .OrderBy(p => p.GetType().Name) .ThenBy(p => p.FriendlyName) .ToList(); var appearance = PaginatedAppearanceOptions.Default with { HelpText = "These are the available bot-specific permissions. " + "Scroll through the pages by using the reactions." }; var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( availablePermissions, p => p.FormatTitle(), p => p.Description, "No permissions available. This is most likely an error." ); return(await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, appearance, ct : this.CancellationToken )); }
public async Task ListServerRoleplaysAsync() { // TODO: Filter so that ones where the user has joined but are private are also included var roleplays = _roleplays.GetRoleplays(this.Context.Guild) .Where(r => r.IsPublic); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Available Roleplays"; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, this.Context.User, roleplays, r => r.Name, r => r.Summary, "There are no roleplays in the server that you can view.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); }
public async Task ListPermissionsAsync() { var availablePermissions = _permissionRegistry.RegisteredPermissions .OrderBy(p => p.GetType().Name) .ThenBy(p => p.FriendlyName); var appearance = PaginatedAppearanceOptions.Default; appearance.HelpText = "These are the available bot-specific permissions. Scroll through the pages by using the reactions."; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, this.Context.User, availablePermissions, p => p.FormatTitle(), p => p.Description, "No permissions available. This is most likely an error.", appearance ); await _interactivity.SendPrivateInteractiveMessageAndDeleteAsync ( this.Context, _feedback, paginatedEmbed, TimeSpan.FromMinutes(5) ); }
public async Task <Result> ListOwnedRoleplaysAsync(IUser?discordUser = null) { discordUser ??= _context.User; var roleplays = await _discordRoleplays.QueryRoleplaysAsync ( q => q .Where(rp => rp.Server.DiscordID == _context.GuildID.Value) .Where(rp => rp.Owner.DiscordID == discordUser.ID) ); var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( roleplays, r => r.Name, r => r.GetSummaryOrDefault(), "You don't have any roleplays." ); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
public async Task ListAutorolesAsync() { var autoroles = new List <AutoroleConfiguration>(); foreach (var role in this.Context.Guild.Roles) { var getAutorole = await _autoroles.GetAutoroleAsync(role); if (!getAutorole.IsSuccess) { continue; } autoroles.Add(getAutorole.Entity); } var pager = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, autoroles, at => $"@{this.Context.Guild.Roles.First(r => r.Id == (ulong)at.DiscordRoleID).Name}", at => at.IsEnabled ? "Enabled" : "Disabled", "There are no autoroles configured." ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, pager, TimeSpan.FromMinutes(5) ); }
public async Task ListDossiersAsync() { var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Dossier Database"; var getDossiersResult = _dossiers.GetDossiers(); if (!getDossiersResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getDossiersResult.ErrorReason); return; } var dossiers = getDossiersResult.Entity; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, this.Context.User, dossiers, d => d.Title, d => d.Summary ?? "No summary set.", "There are no dossiers available.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); }
public async Task <RuntimeResult> ListAvailablePatternsAsync() { var parts = Enum.GetValues(typeof(Pattern)) .Cast <Pattern>() .OrderBy(c => c); var options = new PaginatedAppearanceOptions { Color = Color.DarkPurple }; var paginatedMessage = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, parts, b => b.Humanize(), b => "\u200B", appearance: options ); await _interactivity.SendInteractiveMessageAsync(this.Context.Channel, paginatedMessage); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListDossiersAsync() { var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Dossier Database"; var dossiers = await _dossiers.GetDossiersAsync(); var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, dossiers, d => d.Title, d => d.Summary, "There are no dossiers available.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <IResult> ListNotesAsync(IUser user) { var notes = await _notes.GetNotesAsync(_context.GuildID.Value, user.ID); var createPages = await PaginatedEmbedFactory.PagesFromCollectionAsync ( notes, async note => { var getAuthor = await _userAPI.GetUserAsync(note.Author.DiscordID); if (!getAuthor.IsSuccess) { return(Result <Embed> .FromError(getAuthor)); } var author = getAuthor.Entity; var getAuthorAvatar = CDN.GetUserAvatarUrl(author); var embedFields = new List <EmbedField>(); var eb = new Embed { Title = $"Note #{note.ID} for {user.Username}:{user.Discriminator}", Colour = Color.Gold, Author = new EmbedAuthor(author.Username) { IconUrl = getAuthorAvatar.IsSuccess ? getAuthorAvatar.Entity.ToString() : default(Optional <string>) }, Description = note.Content, Fields = embedFields }; embedFields.Add(new EmbedField("Created", note.CreatedAt.Humanize())); if (note.CreatedAt != note.UpdatedAt) { embedFields.Add(new EmbedField("Last Updated", note.UpdatedAt.Humanize())); } return(eb); } ); if (createPages.Any(p => !p.IsSuccess)) { return(createPages.First(p => !p.IsSuccess)); } var pages = createPages.Select(p => p.Entity).ToList(); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
public async Task <RuntimeResult> ListGrantedPermissionsAsync(IUser discordUser) { var userPermissions = await _permissions.GetApplicableUserPermissionsAsync(this.Context.Guild, discordUser); var permissions = _permissionRegistry.RegisteredPermissions .Where(r => userPermissions.Any(u => u.Permission == r.UniqueIdentifier)) .ToDictionary(p => p.UniqueIdentifier); var permissionInfos = new List <(string Title, string Description)>(); foreach (var permissionGroup in userPermissions.GroupBy(p => p.Permission)) { var permission = permissions[permissionGroup.Key]; var titleBuilder = new StringBuilder(); titleBuilder.Append(permission.FriendlyName); titleBuilder.Append(" ("); var grants = permissionGroup.Select ( up => $"{(up.IsGranted ? ":white_check_mark:" : ":no_entry_sign: ")} {up.Target.Humanize()}" ); titleBuilder.Append(grants.Humanize(",").Transform(To.SentenceCase)); titleBuilder.Append(")"); permissionInfos.Add((titleBuilder.ToString(), permission.Description)); } var appearance = PaginatedAppearanceOptions.Default; appearance.Author = discordUser; appearance.HelpText = "These are the permissions granted to the given user. Scroll through the pages by using the reactions."; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, permissionInfos, p => p.Title, p => p.Description, "No permissions set.", appearance ); await _interactivity.SendPrivateInteractiveMessageAndDeleteAsync ( this.Context, _feedback, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <IResult> ListGrantedPermissionsAsync(IUser discordUser) { var userPermissions = await _permissions.GetApplicableUserPermissionsAsync ( _context.GuildID.Value, discordUser.ID ); var permissions = _permissionRegistry.RegisteredPermissions .Where(r => userPermissions.Any(u => u.Permission == r.UniqueIdentifier)) .ToDictionary(p => p.UniqueIdentifier); var permissionInfos = new List <(string Title, string Description)>(); foreach (var permissionGroup in userPermissions.GroupBy(p => p.Permission)) { var permission = permissions[permissionGroup.Key]; var titleBuilder = new StringBuilder(); titleBuilder.Append(permission.FriendlyName); titleBuilder.Append(" ("); var grants = permissionGroup.Select ( up => $"{(up.IsGranted ? ":white_check_mark:" : ":no_entry_sign: ")} {up.Target.Humanize()}" ); titleBuilder.Append(grants.Humanize(",").Transform(To.SentenceCase)); titleBuilder.Append(')'); permissionInfos.Add((titleBuilder.ToString(), permission.Description)); } var appearance = PaginatedAppearanceOptions.Default with { HelpText = "These are the permissions granted to the given user. " + "Scroll through the pages by using the reactions." }; var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( permissionInfos, p => p.Title, p => p.Description, "No permissions set." ); return(await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, appearance, ct : this.CancellationToken )); }
public async Task <RuntimeResult> ListWarningsAsync(IGuildUser user) { var warnings = await _warnings.GetWarningsAsync(user); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Warnings"; appearance.Color = Color.Orange; var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync ( _feedback, _interactivity, this.Context.User, warnings, async (eb, warning) => { eb.WithTitle($"Warning #{warning.ID} for {user.Username}:{user.Discriminator}"); var author = await this.Context.Guild.GetUserAsync((ulong)warning.Author.DiscordID); eb.WithAuthor(author); eb.WithDescription(warning.Reason); eb.AddField("Created", warning.CreatedAt); if (warning.CreatedAt != warning.UpdatedAt) { eb.AddField("Last Updated", warning.UpdatedAt); } if (warning.IsTemporary) { eb.AddField("Expires On", warning.ExpiresOn); } if (!(warning.MessageID is null)) { // TODO } }, appearance : appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <Result> ShowCharactersAsync(IUser discordUser) { var getCharacters = await _characters.GetUserCharactersAsync ( _context.GuildID.Value, discordUser.ID, this.CancellationToken ); if (!getCharacters.IsSuccess) { return(Result.FromError(getCharacters)); } var getChannel = await _channelAPI.GetChannelAsync(_context.ChannelID, this.CancellationToken); if (!getChannel.IsSuccess) { return(Result.FromError(getChannel)); } var channel = getChannel.Entity; var isChannelNSFW = channel.IsNsfw.IsDefined(out var isNsfw) && isNsfw; var characters = getCharacters.Entity.ToList(); var pages = await PaginatedEmbedFactory.PagesFromCollectionAsync ( characters, async c => { Embed embed; if (c.IsNSFW && !isChannelNSFW) { embed = new Embed(Description: "Redacted (Character is NSFW, but channel is not)"); } else { var createEmbed = await CreateCharacterInfoEmbedAsync(c); if (!createEmbed.IsSuccess) { return(createEmbed); } embed = createEmbed.Entity; } return(embed with { Title = $"{(_context.User.ID == discordUser.ID ? "Your" : $"<@{discordUser.ID}>'s")} characters" }); },
public async Task ListBansAsync(IGuildUser user) { var bans = _bans.GetBans(user); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Bans"; appearance.Color = Color.Orange; var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync ( _feedback, _interactivity, this.Context.User, bans, async (eb, ban) => { eb.WithTitle($"Ban #{ban.ID} for {user.Username}:{user.Discriminator}"); var author = await this.Context.Guild.GetUserAsync((ulong)ban.Author.DiscordID); eb.WithAuthor(author); eb.WithDescription(ban.Reason); eb.AddField("Created", ban.CreatedAt); if (ban.CreatedAt != ban.UpdatedAt) { eb.AddField("Last Updated", ban.UpdatedAt); } if (ban.IsTemporary) { eb.AddField("Expires On", ban.ExpiresOn); } if (!(ban.MessageID is null)) { // TODO } }, appearance : appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5) ); }
public async Task <RuntimeResult> ListOwnedRoleplaysAsync(IGuildUser?discordUser = null) { if (discordUser is null) { var authorUser = this.Context.User; if (!(authorUser is IGuildUser guildUser)) { return(RuntimeCommandResult.FromError("The owner isn't a guild user.")); } discordUser = guildUser; } var getUserRoleplays = await _discordRoleplays.GetUserRoleplaysAsync(discordUser); if (!getUserRoleplays.IsSuccess) { return(getUserRoleplays.ToRuntimeResult()); } var roleplays = getUserRoleplays.Entity.ToList(); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Your roleplays"; appearance.Author = discordUser; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, roleplays, r => r.Name, r => r.Summary, "You don't have any roleplays.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListAvailableBodypartsAsync() { var parts = Enum.GetValues(typeof(Bodypart)) .Cast <Bodypart>() .OrderBy(b => b); var options = new PaginatedAppearanceOptions { Color = Color.DarkPurple }; var paginatedMessage = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, parts, b => b.Humanize(), b => { if (b.IsChiral()) { return("This part is available in both left and right versions."); } if (!b.IsGenderNeutral()) { return("This part is considered NSFW."); } if (b.IsComposite()) { return("This part is composed of smaller parts."); } return("This is a normal bodypart."); }, appearance: options ); await _interactivity.SendInteractiveMessageAsync(this.Context.Channel, paginatedMessage); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListNotesAsync(IGuildUser user) { var notes = await _notes.GetNotesAsync(user); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Notes"; appearance.Color = Color.Gold; var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync ( _feedback, _interactivity, this.Context.User, notes, async (eb, note) => { eb.WithTitle($"Note #{note.ID} for {user.Username}:{user.Discriminator}"); var author = await this.Context.Guild.GetUserAsync((ulong)note.Author.DiscordID); eb.WithAuthor(author); eb.WithDescription(note.Content); eb.AddField("Created", note.CreatedAt); if (note.CreatedAt != note.UpdatedAt) { eb.AddField("Last Updated", note.UpdatedAt); } }, appearance : appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <Result> ListAutorolesAsync() { var autoroles = await _autoroles.GetAutorolesAsync(_context.GuildID.Value, ct : this.CancellationToken); var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( autoroles, at => $"<@&{at.DiscordRoleID}>", at => at.IsEnabled ? "Enabled" : "Disabled", "There are no autoroles configured." ); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
public async Task <Result> ListAvailableTransformationsAsync() { var availableSpecies = await _transformation.GetAvailableSpeciesAsync(); var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( availableSpecies, s => $"{s.Name.Humanize(LetterCasing.Title)} ({s.Name})", s => $"{s.Description}\nWritten by {s.Author}.", "There are no species available." ); pages = pages.Select ( p => p with { Title = "Available species", Colour = Color.MediumPurple }
public async Task <Result> ListUnconfirmedUsersAsync ( [DiscordTypeHint(TypeHint.Role)] AutoroleConfiguration autorole ) { var getUsers = await _autoroles.GetUnconfirmedUsersAsync(autorole); if (!getUsers.IsSuccess) { return(Result.FromError(getUsers)); } var users = getUsers.Entity.ToList(); var getDiscordUsers = await Task.WhenAll ( users.Select(u => _guildAPI.GetGuildMemberAsync(_context.GuildID.Value, u.DiscordID)) ); var discordUsers = getDiscordUsers .Where(r => r.IsSuccess) .Select(r => r.Entity) .Where(u => u.User.HasValue) .ToList(); var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( discordUsers, u => !u.Nickname.HasValue ? $"{u.User.Value.Username}#{u.User.Value.Discriminator} | {u.User.Value.ID}" : $"{u.Nickname} ({u.User.Value.Username}#{u.User.Value.Discriminator} | {u.User.Value.ID})", _ => "Not confirmed", "There are no users that haven't been confirmed for that role." ); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
public async Task <RuntimeResult> ListAvailableTransformationsAsync() { var availableSpecies = await _transformation.GetAvailableSpeciesAsync(); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Available species"; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, availableSpecies, s => $"{s.Name.Humanize(LetterCasing.Title)} ({s.Name})", s => $"{s.Description}\nWritten by {s.Author}.", "There are no species available.", appearance ); if (availableSpecies.Any()) { paginatedEmbed.WithPages ( paginatedEmbed.Pages.Select ( p => p.WithDescription("Use the name inside the parens when transforming body parts.") ) ); } await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListUnconfirmedUsersAsync(AutoroleConfiguration autorole) { var getUsers = await _autoroles.GetUnconfirmedUsersAsync(autorole); if (!getUsers.IsSuccess) { return(getUsers.ToRuntimeResult()); } var users = getUsers.Entity.ToList(); var discordUsers = await Task.WhenAll ( users.Select(u => this.Context.Guild.GetUserAsync((ulong)u.DiscordID)) ); // Filter out users that are no longer in the guild discordUsers = discordUsers.Where(u => !(u is null)).ToArray(); var listMessage = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, discordUsers, u => u.Nickname is null ? $"({u.Username}#{u.Discriminator} | {u.Id})" : $"{u.Nickname} ({u.Username}#{u.Discriminator} | {u.Id})", u => "Not confirmed", "There are no users that haven't been confirmed for that role." ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, listMessage, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task ListOwnedRoleplaysAsync([CanBeNull] IUser discordUser = null) { discordUser = discordUser ?? this.Context.Message.Author; var getUserResult = await _users.GetOrRegisterUserAsync(discordUser); if (!getUserResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getUserResult.ErrorReason); return; } var user = getUserResult.Entity; var roleplays = _roleplays.GetUserRoleplays(user, this.Context.Guild); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Your roleplays"; appearance.Author = discordUser; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, this.Context.User, roleplays, r => r.Name, r => r.Summary ?? "No summary set.", "You don't have any roleplays.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); }
public async Task ListAvailableShadeModifiersAsync() { var parts = Enum.GetValues(typeof(ShadeModifier)) .Cast <ShadeModifier>() .OrderBy(sm => sm); var options = new PaginatedAppearanceOptions { Color = Color.DarkPurple }; var paginatedMessage = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, this.Context.User, parts, b => b.Humanize(), b => "\u200B", appearance: options ); await _interactivity.SendInteractiveMessageAsync(this.Context.Channel, paginatedMessage); }
public async Task ListUnconfirmedUsersAsync(AutoroleConfiguration autorole) { var getUsers = _autoroles.GetUnconfirmedUsers(autorole); if (!getUsers.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getUsers.ErrorReason); return; } var users = await getUsers.Entity.ToListAsync(); var discordUsers = await Task.WhenAll ( users.Select(u => this.Context.Guild.GetUserAsync((ulong)u.DiscordID)) ); var listMessage = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, discordUsers, u => $"{u.Nickname} ({u.Username}#{u.Discriminator} | {u.Id})", u => "Not confirmed", "There are no users that haven't been confirmed for that role." ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, listMessage, TimeSpan.FromMinutes(5) ); }
public async Task <Result> ListServerRoleplaysAsync() { var roleplays = await _discordRoleplays.QueryRoleplaysAsync ( q => q .Where(rp => rp.Server.DiscordID == _context.GuildID.Value) .Where(rp => rp.IsPublic) ); var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection ( roleplays, r => r.Name, r => r.GetSummaryOrDefault(), "There are no roleplays in the server that you can view." ); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
public async Task <RuntimeResult> ListServerRoleplaysAsync() { var getRoleplays = await _discordRoleplays.GetRoleplaysAsync(this.Context.Guild); if (!getRoleplays.IsSuccess) { return(getRoleplays.ToRuntimeResult()); } var roleplays = getRoleplays.Entity.Where(r => r.IsPublic).ToList(); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Available Roleplays"; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, roleplays, r => r.Name, r => r.Summary, "There are no roleplays in the server that you can view.", appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListBansAsync() { var bans = await _bans.GetBansAsync(this.Context.Guild); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Bans"; appearance.Color = Color.Orange; var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync ( _feedback, _interactivity, this.Context.User, bans, async (eb, ban) => { IUser?bannedUser = null; if (this.Context.Client is DiscordSocketClient socketClient) { bannedUser = await socketClient.Rest.GetUserAsync((ulong)ban.User.DiscordID); } if (bannedUser is null) { eb.WithTitle($"Ban #{ban.ID} for user with ID {ban.User.DiscordID}"); } else { eb.WithTitle($"Ban #{ban.ID} for {bannedUser.Username}:{bannedUser.Discriminator}"); } var author = await this.Context.Guild.GetUserAsync((ulong)ban.Author.DiscordID); eb.WithAuthor(author); eb.WithDescription(ban.Reason); eb.AddField("Created", ban.CreatedAt); if (ban.CreatedAt != ban.UpdatedAt) { eb.AddField("Last Updated", ban.UpdatedAt); } if (ban.IsTemporary) { eb.AddField("Expires On", ban.ExpiresOn); } if (!(ban.MessageID is null)) { // TODO } }, appearance : appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <IResult> ListBansAsync() { var bans = await _bans.GetBansAsync(_context.GuildID.Value); var createPages = await PaginatedEmbedFactory.PagesFromCollectionAsync ( bans, async ban => { var getBanAuthor = await _userAPI.GetUserAsync(ban.Author.DiscordID); if (!getBanAuthor.IsSuccess) { return(Result <Embed> .FromError(getBanAuthor)); } var banAuthor = getBanAuthor.Entity; var getBannedUser = await _userAPI.GetUserAsync(ban.User.DiscordID); if (!getBannedUser.IsSuccess) { return(Result <Embed> .FromError(getBannedUser)); } var bannedUser = getBanAuthor.Entity; var getBanAuthorAvatar = CDN.GetUserAvatarUrl(banAuthor); var embedFields = new List <IEmbedField>(); var eb = new Embed { Title = $"Ban #{ban.ID} for {bannedUser.Username}:{bannedUser.Discriminator}", Colour = Color.Orange, Author = new EmbedAuthor(banAuthor.Username) { Url = getBanAuthorAvatar.IsSuccess ? getBanAuthorAvatar.Entity.ToString() : default(Optional <string>) }, Description = ban.Reason, Fields = embedFields }; embedFields.Add(new EmbedField("Created", ban.CreatedAt.Humanize())); if (ban.CreatedAt != ban.UpdatedAt) { embedFields.Add(new EmbedField("Last Updated", ban.UpdatedAt.Humanize())); } if (ban.ExpiresOn.HasValue) { embedFields.Add(new EmbedField("Expires On", ban.ExpiresOn.Humanize())); } if (ban.MessageID is not null) { // TODO } return(eb); } ); if (createPages.Any(p => !p.IsSuccess)) { return(createPages.First(p => !p.IsSuccess)); } var pages = createPages.Select(p => p.Entity).ToList(); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }