public async Task Roles(string arg0) { // Possible cases: // 1. <role> // 2. <species> // If a role with this name exists, that's what we'll prioritize (users can use the genus + species overload if they need to). // If no such role exists, check for a species with this name instead. Common.Roles.IRole role = await Db.GetRoleAsync(arg0); if (role.IsValid()) { // The role is valid. // List all extant species with this role. IEnumerable <ISpecies> species = (await Db.GetSpeciesAsync(role)) .Where(s => !s.IsExtinct()) .OrderBy(s => s.GetShortName()); IEnumerable <Discord.Messaging.IEmbed> pages = EmbedUtilities.CreateEmbedPages($"Extant species with this role ({species.Count()}):", species, options: EmbedPaginationOptions.AddPageNumbers); foreach (Discord.Messaging.IEmbed page in pages) { page.Title = $"Role: {role.GetName()}"; page.Description = role.GetDescriptionOrDefault(); } await ReplyAsync(new Discord.Messaging.PaginatedMessage(pages)); } else { // The role is not valid. IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(string.Empty, arg0); if (matchingSpecies.Count() > 0) { ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies); if (species.IsValid()) { await ReplyRolesAsync(matchingSpecies.First()); } } else { // There were no matching species, so just say that the role is invalid. await this.ReplyValidateRoleAsync(role); } } }
public async Task SetRoleDescription(string roleName, string description) { Common.Roles.IRole role = await this.GetRoleOrReplyAsync(roleName); if (role.IsValid()) { role.Description = description; await Db.UpdateRoleAsync(role); await ReplySuccessAsync($"Successfully updated description for role {role.GetName().ToBold()}."); } }
public async Task RemoveRole(string genusName, string speciesName, string roleName) { // Get the species. ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName); if (species.IsValid()) { // Get the role. Common.Roles.IRole role = await Db.GetRoleAsync(roleName); if (await this.ReplyValidateRoleAsync(role)) { // Update the species. await Db.RemoveRoleAsync(species, role); await ReplySuccessAsync($"Role {role.GetName().ToBold()} has successfully been unassigned from {species.GetShortName().ToBold()}."); } } }
public async Task SetRole(string genusName, string speciesName, string roleName, string notes = "") { // Get the species. ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName); if (species.IsValid()) { // Get the role. Common.Roles.IRole role = await Db.GetRoleAsync(roleName); if (await this.ReplyValidateRoleAsync(role)) { // Update the species. role.Notes = notes; await Db.AddRoleAsync(species, role); await ReplySuccessAsync($"{species.GetShortName().ToBold()} has successfully been assigned the role of {role.GetName().ToBold()}."); } } }