Esempio n. 1
0
        private async Task SetSpeciesCommonName(string genus, string species, string commonName)
        {
            Species species_info = await BotUtils.ReplyFindSpeciesAsync(Context, genus, species);

            if (species_info is null)
            {
                return;
            }

            // Ensure that the user has necessary privileges to use this command.
            if (!await BotUtils.ReplyHasPrivilegeOrOwnershipAsync(Context, PrivilegeLevel.ServerModerator, species_info))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(commonName))
            {
                // If the given common name is empty, erase all common names associated with this species.
                await SpeciesUtils.RemoveCommonNamesAsync(species_info);

                await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully removed all common names from **{0}**.",
                                                                         species_info.ShortName));
            }
            else
            {
                // Otherwise, add the common name to the database.

                // The difference between this and the "+common" command is that this one overwrites the value stored in the "Species" table.
                // This field is pretty much deprected at this point, but it is still accessed through some generic taxon commands.

                await SpeciesUtils.AddCommonNameAsync(species_info, commonName, overwriteSpeciesTable : true);

                await BotUtils.ReplyAsync_Success(Context, string.Format("**{0}** is now commonly known as the **{1}**.",
                                                                         species_info.ShortName,
                                                                         StringUtils.ToTitleCase(commonName)));
            }
        }