public async Task SetCommonName(string taxon, string commonName) { // Ensure that the user has necessary privileges to use this command. if (!await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator)) { return; } // Get all taxa with the specified name. Taxon[] taxa = await BotUtils.GetTaxaFromDb(taxon); if (taxa.Count() <= 0) { // If there is no such taxon, default to showing species suggestions. await BotUtils.ReplyAsync_SpeciesSuggestions(Context, "", taxon); } else if (taxa.Count() == 1 && taxa[0].type == TaxonRank.Species) { // If there's a single result, and it's a species, use the species-specific update procedure. // (The generic one works fine, but this currently shows a unique confirmation message.) await SetSpeciesCommonName(taxon, commonName); } else if (await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa)) { // If we got a single taxon, update the common name for that taxon. await _setTaxonCommonNameAsync(taxa[0], commonName); } }
public async Task GetInfo(string name) { // Prioritize species first. Species[] species = await BotUtils.GetSpeciesFromDb("", name); if (species.Count() > 0) { if (await BotUtils.ReplyValidateSpeciesAsync(Context, species)) { await SpeciesCommands.ShowSpeciesInfoAsync(Context, species[0]); } } else { // Otherwise, show other taxon. Taxon[] taxa = await BotUtils.GetTaxaFromDb(name); if (taxa.Count() <= 0) { // This command was traditionally used with species, so show the user species suggestions in the event of no matches. await BotUtils.ReplyAsync_SpeciesSuggestions(Context, "", name, async (BotUtils.ConfirmSuggestionArgs args) => await GetInfo(args.Suggestion)); } else if (await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa)) { await BotUtils.Command_ShowTaxon(Context, taxa[0].type, name); } } }
public async Task SetTaxonDescription(string taxon) { // Get all taxa with the specified name. Taxon[] taxa = await BotUtils.GetTaxaFromDb(taxon); if (taxa.Count() <= 0) { // If there is no such taxon, default to showing species suggestions. await BotUtils.ReplyAsync_SpeciesSuggestions(Context, "", taxon); } else if (await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa)) { // If we got a single taxon, begin a multistage update for that taxon. await _setTaxonDescriptionAsync(taxa[0]); } }
public async Task SetTaxonDescription(string taxonNameOrGenus, string descriptionOrSpecies) { // Either the user provided a taxon and a description, or they provided a genus and species and want to use a two-part command sequence. // If the species exists, we'll use the two-part command version. If it doesn't, we'll assume the user was providing a description directly. Species[] species_list = await BotUtils.GetSpeciesFromDb(taxonNameOrGenus, descriptionOrSpecies); if (species_list.Count() <= 0) { // No such species exists for the given genus/species, so look for the taxon instead and try to update its description directly. Taxon[] taxa = await BotUtils.GetTaxaFromDb(taxonNameOrGenus); // If we didn't get any matches, show the user species suggestions. if (taxa.Count() <= 0) { await BotUtils.ReplyFindSpeciesAsync(Context, "", taxonNameOrGenus); } else { // Make sure we have one, and only one taxon to update. if (!await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa)) { return; } Taxon taxon = taxa[0]; if (taxon.type == TaxonRank.Species) { // If the taxon is a species, use the species update procedure. await _setSpeciesDescriptionAsync(await BotUtils.GetSpeciesFromDb(taxon.id), descriptionOrSpecies); } else { // Update the taxon in the DB. await BotUtils.Command_SetTaxonDescription(Context, taxon, descriptionOrSpecies); } } } else if (await BotUtils.ReplyValidateSpeciesAsync(Context, species_list)) { // A species exists with the given genus/species, so initiate a two-part command. // Ensure that the user has necessary privileges to use this command. if (!await BotUtils.ReplyHasPrivilegeOrOwnershipAsync(Context, PrivilegeLevel.ServerModerator, species_list[0])) { return; } Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context) { UserData = new string[] { taxonNameOrGenus, descriptionOrSpecies }, Callback = async(args) => { Species[] species = await BotUtils.GetSpeciesFromDb(args.Message.UserData[0], args.Message.UserData[1]); if (await BotUtils.ReplyValidateSpeciesAsync(args.Message.Context, species)) { await _setSpeciesDescriptionAsync(species[0], args.ResponseContent); } } }; await Bot.DiscordUtils.SendMessageAsync(Context, p, string.Format("Reply with the description for **{0}**.\nTo cancel the update, reply with \"cancel\".", species_list[0].ShortName)); } }