private async Task <bool> _checkTrophy_helper_hasSpeciesWithZoneDescriptionMatch(TrophyScanner.ScannerQueueItem item, string regexPattern) { // Get all zones. List <Zone> zones = new List <Zone>(await BotUtils.GetZonesFromDb()); // Filter list so we only have zones with cold climates. zones.RemoveAll(zone => !Regex.IsMatch(zone.Description, regexPattern)); // Check if the user has any species in these zones. string username = (await item.Context.Guild.GetUserAsync(item.UserId)).Username; bool unlocked = false; foreach (Zone zone in zones) { using (SQLiteCommand cmd = new SQLiteCommand("SELECT COUNT(*) FROM SpeciesZones WHERE zone_id=$zone_id AND species_id IN (SELECT id FROM Species WHERE owner=$owner);")) { cmd.Parameters.AddWithValue("$zone_id", zone.Id); cmd.Parameters.AddWithValue("$owner", username); if (await Database.GetScalar <long>(cmd) > 0) { unlocked = true; break; } } } return(unlocked); }
public async Task MinusZone(string genus, string species, string zoneList) { // Ensure that the user has necessary privileges to use this command. if (!await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator)) { return; } // Get the specified species. Species sp = await BotUtils.ReplyFindSpeciesAsync(Context, genus, species); if (sp is null) { return; } // Get the zones that the species currently resides in. // These will be used to show warning messages (e.g., doesn't exist in the given zone). long[] current_zone_ids = (await BotUtils.GetZonesFromDb(sp.Id)).Select(x => x.Id).ToArray(); // Get the zones from user input. ZoneListResult zones = await ZoneUtils.GetZonesByZoneListAsync(zoneList); // Remove the zones from the species. await SpeciesUtils.RemoveZonesAsync(sp, zones.Zones); if (zones.InvalidZones.Count() > 0) { // Show a warning if the user provided any invalid zones. await BotUtils.ReplyAsync_Warning(Context, string.Format("{0} {1} not exist.", StringUtils.ConjunctiveJoin(", ", zones.InvalidZones.Select(x => string.Format("**{0}**", ZoneUtils.FormatZoneName(x))).ToArray()), zones.InvalidZones.Count() == 1 ? "does" : "do")); } if (zones.Zones.Any(x => !current_zone_ids.Contains(x.Id))) { // Show a warning if the species wasn't in one or more of the zones provided. await BotUtils.ReplyAsync_Warning(Context, string.Format("**{0}** is already absent from {1}.", sp.ShortName, StringUtils.ConjunctiveJoin(", ", zones.Zones.Where(x => !current_zone_ids.Contains(x.Id)).Select(x => string.Format("**{0}**", x.GetFullName())).ToArray()))); } if (zones.Zones.Any(x => current_zone_ids.Contains(x.Id))) { // Show a confirmation of all valid zones. await BotUtils.ReplyAsync_Success(Context, string.Format("**{0}** no longer inhabits {1}.", sp.ShortName, StringUtils.DisjunctiveJoin(", ", zones.Zones.Where(x => current_zone_ids.Contains(x.Id)).Select(x => string.Format("**{0}**", x.GetFullName())).ToArray()))); } }
private async Task ApplyPostMatchModifierAsync(SearchQueryResult result, string modifier) { int split_index = modifier.IndexOf(':'); string name = modifier.Substring(0, split_index).Trim(); string value = modifier.Substring(split_index + 1, modifier.Length - split_index - 1).Trim(); bool subtract = name.Length > 0 ? name[0] == '-' : false; if (name.StartsWith("-")) { name = name.Substring(1, name.Length - 1); } // Trim outer quotes from the value. if (value.Length > 0 && value.First() == '"' && value.Last() == '"') { value = value.Trim('"'); } switch (name) { case "groupby": case "group": // Applies grouping to the species based on the given attribute. switch (value.ToLower()) { case "z": case "zones": case "zone": await result.GroupByAsync(async (x) => { return((await BotUtils.GetZonesFromDb(x.Id)).Select(z => z.GetFullName()).ToArray()); }); break; case "g": case "genus": await result.GroupByAsync((x) => { return(Task.FromResult(new string[] { x.GenusName })); }); break; case "f": case "family": await result.GroupByAsync(async (x) => { Taxon taxon = (await BotUtils.GetFullTaxaFromDb(x)).Family; return(new string[] { taxon is null ? "N/A" : taxon.GetName() }); }); break;