public async Task <RuntimeResult> ListAvailableRolesAsync() { var getServerRolesResult = await _characterRoles.GetCharacterRolesAsync(this.Context.Guild); if (!getServerRolesResult.IsSuccess) { return(getServerRolesResult.ToRuntimeResult()); } var serverRoles = getServerRolesResult.Entity.ToList(); var eb = _feedback.CreateEmbedBase(); eb.WithTitle("Available character roles"); eb.WithDescription ( "These are the roles you can apply to your characters to automatically switch you to that role " + "when you assume the character.\n" + "\n" + "In order to avoid mentioning everyone that has the role, use the numerical ID or role name" + " instead of the actual mention. The ID is listed below along with the role name." ); if (!serverRoles.Any()) { eb.WithFooter("There aren't any character roles available in this server."); } else { foreach (var characterRole in serverRoles) { var discordRole = this.Context.Guild.GetRole((ulong)characterRole.DiscordID); if (discordRole is null) { continue; } var ef = new EmbedFieldBuilder(); ef.WithName($"{discordRole.Name} ({discordRole.Id})"); var roleStatus = characterRole.Access == RoleAccess.Open ? "open to everyone" : "restricted"; ef.WithValue($"*This role is {roleStatus}.*"); eb.AddField(ef); } } await _feedback.SendEmbedAsync(this.Context.Channel, eb.Build()); return(RuntimeCommandResult.FromSuccess()); }
public async Task <Result> ListAvailableRolesAsync() { var baseEmbed = new Embed { Colour = _feedback.Theme.Secondary, Title = "Available character roles", Description = "These are the roles you can apply to your characters to automatically switch you " + "to that role when you assume the character.\n" + "\n" + "In order to avoid mentioning everyone that has the role, use the numerical ID or " + "role name instead of the actual mention. The ID is listed below along with the " + "role name." }; var getCharacterRoles = await _characterRoles.GetCharacterRolesAsync(_context.GuildID.Value); if (!getCharacterRoles.IsSuccess) { return(Result.FromError(getCharacterRoles)); } var characterRoles = getCharacterRoles.Entity; if (!characterRoles.Any()) { baseEmbed = baseEmbed with { Footer = new EmbedFooter("There aren't any character roles available in this server.") }; return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, new[] { baseEmbed }, ct : this.CancellationToken )); } var getGuildRoles = await _guildAPI.GetGuildRolesAsync(_context.GuildID.Value, this.CancellationToken); if (!getGuildRoles.IsSuccess) { return(Result.FromError(getGuildRoles)); } var guildRoles = getGuildRoles.Entity; var fields = characterRoles.Select ( r => { var guildRole = guildRoles.FirstOrDefault(gr => gr.ID == r.DiscordID); var roleStatus = r.Access == RoleAccess.Open ? "open to everyone" : "restricted"; var name = guildRole is null ? $"??? ({r.DiscordID} - this role appears to be deleted.)" : $"{guildRole.Name} ({r.DiscordID})"; var value = $"*This role is {roleStatus}.*"; return(new EmbedField(name, value)); } ); var pages = PageFactory.FromFields(fields, pageBase: baseEmbed); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }