public async Task AddSpecies(string genus, string species, string zone = "", string description = "") { // Check if the species already exists before attempting to add it. if ((await BotUtils.GetSpeciesFromDb(genus, species)).Count() > 0) { await BotUtils.ReplyAsync_Warning(Context, string.Format("The species \"{0}\" already exists.", BotUtils.GenerateSpeciesName(genus, species))); return; } await BotUtils.AddGenusToDb(genus); Taxon genus_info = await BotUtils.GetGenusFromDb(genus); using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO Species(name, description, genus_id, owner, timestamp, user_id) VALUES($name, $description, $genus_id, $owner, $timestamp, $user_id);")) { cmd.Parameters.AddWithValue("$name", species.ToLower()); cmd.Parameters.AddWithValue("$description", description); cmd.Parameters.AddWithValue("$genus_id", genus_info.id); cmd.Parameters.AddWithValue("$owner", Context.User.Username); cmd.Parameters.AddWithValue("$user_id", Context.User.Id); cmd.Parameters.AddWithValue("$timestamp", DateTimeOffset.UtcNow.ToUnixTimeSeconds()); await Database.ExecuteNonQuery(cmd); } Species[] sp_list = await BotUtils.GetSpeciesFromDb(genus, species); Species sp = sp_list.Count() > 0 ? sp_list[0] : null; long species_id = sp == null ? -1 : sp.Id; if (species_id < 0) { await BotUtils.ReplyAsync_Error(Context, "Failed to add species (invalid Species ID)."); return; } // Add to all given zones. await _plusZone(sp, zone, string.Empty, onlyShowErrors : true); // Add the user to the trophy scanner queue in case their species earned them any new trophies. if (OurFoodChainBot.Instance.Config.TrophiesEnabled) { await Global.TrophyScanner.AddToQueueAsync(Context, Context.User.Id); } await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully created new species, **{0}**.", BotUtils.GenerateSpeciesName(genus, species))); }
public async Task SetSpecies(string genus, string species, string newName) { // Get the specified species. Species sp = await BotUtils.ReplyFindSpeciesAsync(Context, genus, species); if (sp is null) { return; } // Update the species. using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Species SET name=$name WHERE id=$species_id;")) { cmd.Parameters.AddWithValue("$name", newName.ToLower()); cmd.Parameters.AddWithValue("$species_id", sp.Id); await Database.ExecuteNonQuery(cmd); } await BotUtils.ReplyAsync_Success(Context, string.Format("**{0}** has been successfully renamed to **{1}**.", sp.ShortName, BotUtils.GenerateSpeciesName(sp.GenusName, newName))); }