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 AddGenus(string genus, string description = "") { // Make sure that the genus doesn't already exist. if (!(await BotUtils.GetGenusFromDb(genus) is null)) { await BotUtils.ReplyAsync_Warning(Context, string.Format("The genus **{0}** already exists.", StringUtils.ToTitleCase(genus))); return; } Taxon genus_info = new Taxon(TaxonRank.Genus) { name = genus, description = description }; await BotUtils.AddGenusToDb(genus_info); await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully created new genus, **{0}**.", StringUtils.ToTitleCase(genus))); }