Пример #1
0
        private async Task _addPrey(string genusName, string speciesName, string[] preySpeciesNames, string notes)
        {
            Species predator = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName);

            if (predator != null)
            {
                List <Species> prey_list   = new List <Species>();
                List <string>  failed_prey = new List <string>();

                foreach (string prey_species_name in preySpeciesNames)
                {
                    Species prey = await SpeciesUtils.GetUniqueSpeciesAsync(prey_species_name);

                    if (prey is null)
                    {
                        failed_prey.Add(prey_species_name);
                    }
                    else
                    {
                        prey_list.Add(prey);
                    }
                }

                if (failed_prey.Count() > 0)
                {
                    await BotUtils.ReplyAsync_Warning(Context, string.Format("The following species could not be determined: {0}.",
                                                                             StringUtils.ConjunctiveJoin(", ", failed_prey.Select(x => string.Format("**{0}**", StringUtils.ToTitleCase(x))).ToArray())));
                }

                if (prey_list.Count() > 0)
                {
                    await _addPrey(predator, prey_list.ToArray(), notes);
                }
            }
        }
Пример #2
0
        public async Task AddPrey(string arg0, string arg1, string arg2)
        {
            // We have the following possibilities, which we will check for in-order:
            // <genusName> <speciesName> <preySpeciesName>
            // <speciesName> <preyGenusName> <preySpeciesName>
            // <speciesName> <preySpecieName> <Notes>

            // If the user provided a prey list, it's easier to determine what they meant-- Check for that first.

            if (_isSpeciesList(arg1))
            {
                // <speciesName> <preyList> <notes>
                await _addPrey(string.Empty, arg0, _splitSpeciesList(arg1), arg2);
            }
            else
            {
                Species species = null, preySpecies = null;
                string  notes = string.Empty;

                // <genusName> <speciesName> <preyList>

                species = await SpeciesUtils.GetUniqueSpeciesAsync(arg0, arg1);

                if (species != null && _isSpeciesList(arg2))
                {
                    await _addPrey(arg0, arg1, _splitSpeciesList(arg2), string.Empty);
                }
                else
                {
                    // <genusName> <speciesName> <preySpeciesName>

                    preySpecies = species is null ? null : await SpeciesUtils.GetUniqueSpeciesAsync(arg2);

                    notes = string.Empty;

                    if (species is null || preySpecies is null)
                    {
                        // <speciesName> <preyGenusName> <preySpeciesName>

                        species = await SpeciesUtils.GetUniqueSpeciesAsync(arg0);

                        preySpecies = species is null ? null : await SpeciesUtils.GetUniqueSpeciesAsync(arg1, arg2);

                        notes = string.Empty;
                    }

                    if (species is null || preySpecies is null)
                    {
                        // <speciesName> <preySpeciesName> <Notes>

                        species = await SpeciesUtils.GetUniqueSpeciesAsync(arg0);

                        preySpecies = species is null ? null : await SpeciesUtils.GetUniqueSpeciesAsync(arg1);

                        notes = arg2;
                    }

                    if (species is null)
                    {
                        await BotUtils.ReplyAsync_Error(Context, "The given species does not exist.");
                    }
                    else if (preySpecies is null)
                    {
                        await BotUtils.ReplyAsync_Error(Context, "The given prey species does not exist.");
                    }
                    else
                    {
                        await _addPrey(species, new Species[] { preySpecies }, notes);
                    }
                }
            }
        }