Example #1
0
        private async Task _appendDescriptionAsync(Species species)
        {
            Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context)
            {
                Callback = async(args) => {
                    if (await BotUtils.ReplyValidateSpeciesAsync(args.Message.Context, species))
                    {
                        await _appendDescriptionAsync(species, args.ResponseContent);
                    }
                }
            };

            await Bot.DiscordUtils.SendMessageAsync(Context, p,
                                                    string.Format("Reply with the text to append to the description for **{0}**.\nTo cancel the update, reply with \"cancel\".", species.ShortName));
        }
Example #2
0
        // Private members

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

            Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context)
            {
                Callback = async(args) => {
                    if (await BotUtils.ReplyValidateSpeciesAsync(args.Message.Context, species))
                    {
                        await _setSpeciesDescriptionAsync(species, args.ResponseContent);
                    }
                }
            };

            await Bot.DiscordUtils.SendMessageAsync(Context, p,
                                                    string.Format("Reply with the description for **{0}**.\nTo cancel the update, reply with \"cancel\".", species.ShortName));
        }
Example #3
0
        private async Task _setTaxonDescriptionAsync(Taxon taxon)
        {
            if (taxon.type == TaxonRank.Species)
            {
                await _setSpeciesDescriptionAsync(await SpeciesUtils.GetSpeciesAsync(taxon.id));
            }

            else if (await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator))   // moderator use only

            {
                Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context)
                {
                    UserData = new string[] { taxon.name },
                    Callback = async(args) => {
                        await BotUtils.Command_SetTaxonDescription(args.Message.Context, taxon, args.ResponseContent);
                    }
                };

                await Bot.DiscordUtils.SendMessageAsync(Context, p,
                                                        string.Format("Reply with the description for {0} **{1}**.\nTo cancel the update, reply with \"cancel\".", taxon.GetTypeName(), taxon.GetName()));
            }
        }
Example #4
0
        public async Task SetTaxonDescription(string taxonNameOrGenus, string descriptionOrSpecies)
        {
            // Either the user provided a taxon and a description, or they provided a genus and species and want to use a two-part command sequence.
            // If the species exists, we'll use the two-part command version. If it doesn't, we'll assume the user was providing a description directly.

            Species[] species_list = await BotUtils.GetSpeciesFromDb(taxonNameOrGenus, descriptionOrSpecies);

            if (species_list.Count() <= 0)
            {
                // No such species exists for the given genus/species, so look for the taxon instead and try to update its description directly.

                Taxon[] taxa = await BotUtils.GetTaxaFromDb(taxonNameOrGenus);

                // If we didn't get any matches, show the user species suggestions.

                if (taxa.Count() <= 0)
                {
                    await BotUtils.ReplyFindSpeciesAsync(Context, "", taxonNameOrGenus);
                }

                else
                {
                    // Make sure we have one, and only one taxon to update.

                    if (!await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa))
                    {
                        return;
                    }

                    Taxon taxon = taxa[0];

                    if (taxon.type == TaxonRank.Species)
                    {
                        // If the taxon is a species, use the species update procedure.
                        await _setSpeciesDescriptionAsync(await BotUtils.GetSpeciesFromDb(taxon.id), descriptionOrSpecies);
                    }

                    else
                    {
                        // Update the taxon in the DB.
                        await BotUtils.Command_SetTaxonDescription(Context, taxon, descriptionOrSpecies);
                    }
                }
            }
            else if (await BotUtils.ReplyValidateSpeciesAsync(Context, species_list))
            {
                // A species exists with the given genus/species, so initiate a two-part command.

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

                Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context)
                {
                    UserData = new string[] { taxonNameOrGenus, descriptionOrSpecies },
                    Callback = async(args) => {
                        Species[] species = await BotUtils.GetSpeciesFromDb(args.Message.UserData[0], args.Message.UserData[1]);

                        if (await BotUtils.ReplyValidateSpeciesAsync(args.Message.Context, species))
                        {
                            await _setSpeciesDescriptionAsync(species[0], args.ResponseContent);
                        }
                    }
                };

                await Bot.DiscordUtils.SendMessageAsync(Context, p,
                                                        string.Format("Reply with the description for **{0}**.\nTo cancel the update, reply with \"cancel\".", species_list[0].ShortName));
            }
        }