示例#1
0
        public async Task AddPrey(string genusName, string speciesName, string preyGenusName, string preySpeciesName, string notes)
        {
            ISpecies predatorSpecies = await GetSpeciesOrReplyAsync(genusName, speciesName);

            ISpecies preySpecies = predatorSpecies.IsValid() ? await GetSpeciesOrReplyAsync(preyGenusName, preySpeciesName) : null;

            if (predatorSpecies.IsValid() && preySpecies.IsValid())
            {
                await ReplyAddPreyAsync(predatorSpecies, new ISpecies[] { preySpecies }, notes);
            }
        }
示例#2
0
        public async Task RemovePrey(string genusName, string speciesName, string preyGenusName, string preySpeciesName)
        {
            ISpecies predatorSpecies = await GetSpeciesOrReplyAsync(genusName, speciesName);

            ISpecies preySpecies = predatorSpecies.IsValid() ? await GetSpeciesOrReplyAsync(preyGenusName, preySpeciesName) : null;

            if (predatorSpecies.IsValid() && preySpecies.IsValid())
            {
                await ReplyRemovePreyAsync(predatorSpecies, preySpecies);
            }
        }
示例#3
0
        public async Task <ISpeciesAmbiguityResolverResult> ReplyResolveAmbiguityAsync(string arg0, string arg1, string arg2, string arg3 = "", AmbiguityResolverOptions options = AmbiguityResolverOptions.None)
        {
            ISpeciesAmbiguityResolver       resolver = new SpeciesAmbiguityResolver(await GetDatabaseAsync());
            ISpeciesAmbiguityResolverResult result   = string.IsNullOrWhiteSpace(arg3) ? await resolver.Resolve2SpeciesAsync(arg0, arg1, arg2, options) : await resolver.Resolve2SpeciesAsync(arg0, arg1, arg2, arg3, options);

            ISpecies species1 = null;
            ISpecies species2 = null;

            if (result.First.Count() > 1)
            {
                await ReplyValidateSpeciesAsync(result.First); // show matching species
            }
            else if (!result.First.Any())
            {
                await ReplyErrorAsync("The first species could not be determined.");
            }
            else
            {
                species1 = result.First.First();
            }

            if (species1.IsValid())
            {
                if (result.Second.Count() > 1)
                {
                    await ReplyValidateSpeciesAsync(result.Second); // show matching species
                }
                else if (!result.Second.Any())
                {
                    if (!string.IsNullOrWhiteSpace(result.SuggestionHint))
                    {
                        species2 = await GetSpeciesOrReplyAsync(result.SuggestionHint);
                    }

                    if (!species2.IsValid())
                    {
                        await ReplyErrorAsync("The second species could not be determined.");
                    }
                }
                else
                {
                    species2 = result.Second.First();
                }
            }

            if (species1.IsValid() && species2.IsValid())
            {
                return(new SpeciesAmbiguityResolverResult(new ISpecies[] { species1 }, new ISpecies[] { species2 }, result.SuggestionHint, result.Extra));
            }

            return(result); // not success
        }
示例#4
0
        public async Task SetArtist(string genusName, string speciesName, int pictureIndex, string artist)
        {
            // Decrease the picture index by 1 (since users are expected to use the indices as shown by the "gallery" command, which begin at 1).

            --pictureIndex;

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                IEnumerable <IPicture> pictures = await Db.GetPicturesAsync(species);

                if (pictureIndex >= 0 && pictureIndex < pictures.Count())
                {
                    IPicture picture = pictures.ElementAt(pictureIndex);
                    picture.Artist = new Creator(artist);

                    await Db.AddPictureAsync(species, picture);

                    await ReplySuccessAsync(string.Format("Successfully updated artist for {0} [picture]({1}) to **{2}**.",
                                                          StringUtilities.ToPossessive(species.GetShortName()),
                                                          picture.Url,
                                                          artist));
                }
                else
                {
                    await ReplyErrorAsync(string.Format("**{0}** has no picture at this index.", species.GetShortName()));
                }
            }
        }
示例#5
0
        public async Task MinusPic(string genusName, string speciesName, int pictureIndex)
        {
            // Decrease the picture index by 1 (since users are expected to use the indices as shown by the "gallery" command, which begin at 1).

            --pictureIndex;

            // Get the species.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                IEnumerable <IPicture> pictures = await Db.GetPicturesAsync(species);

                IPicture picture = (pictureIndex >= 0 && pictureIndex < pictures.Count()) ? pictures.ElementAt(pictureIndex) : null;

                // If the image was removed from anywhere (gallery or default species picture), this is set to "true".

                bool success = await Db.RemovePictureAsync(species, picture);

                if (success)
                {
                    await ReplySuccessAsync($"Successfully removed {picture.Url.ToLink("picture")} from {species.GetShortName().ToBold()}.");
                }
                else
                {
                    await ReplySuccessAsync($"{species.GetShortName().ToBold()} has no picture at this index.");
                }
            }
        }
示例#6
0
        public async Task AppendDescription(string arg0, string arg1)
        {
            // Possible cases:
            // 1. <genus> <species>
            // 2. <species> <description>

            IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(arg0, arg1);

            if (matchingSpecies.Count() <= 0)
            {
                // We did not get any matching species, so we must have case (2) (or invalid genus/species).

                await AppendDescription(string.Empty, arg0, arg1);
            }
            else
            {
                // We got at least one matching species, so we have case (1).

                ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies);

                if (species.IsValid())
                {
                    await ReplyAppendDescriptionAsync(species);
                }
            }
        }
示例#7
0
        private async Task ReplyAddPreyAsync(string genusName, string speciesName, IEnumerable <string> preySpeciesNames, string notes)
        {
            ISpecies predator = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (predator.IsValid())
            {
                List <ISpecies> preyList   = new List <ISpecies>();
                List <string>   failedPrey = new List <string>();

                foreach (string preySpeciesName in preySpeciesNames)
                {
                    ISpecies prey = await Db.GetUniqueSpeciesAsync(preySpeciesName);

                    if (prey is null)
                    {
                        failedPrey.Add(preySpeciesName);
                    }
                    else
                    {
                        preyList.Add(prey);
                    }
                }

                if (failedPrey.Count() > 0)
                {
                    await ReplyWarningAsync(string.Format("The following species could not be determined: {0}.",
                                                          StringUtilities.ConjunctiveJoin(failedPrey.Select(x => string.Format("**{0}**", StringUtilities.ToTitleCase(x))))));
                }

                if (preyList.Count() > 0)
                {
                    await ReplyAddPreyAsync(predator, preyList.ToArray(), notes);
                }
            }
        }
示例#8
0
        private async Task ReplyAppendDescriptionAsync(ISpecies species, string append)
        {
            const int maxLength = 10000;

            if (species.IsValid())
            {
                StringBuilder sb = new StringBuilder(species.Description.SafeTrim());

                // Add new text as a new paragraph.

                sb.AppendLine();
                sb.AppendLine();
                sb.Append(append.SafeTrim());

                if (sb.Length > maxLength)
                {
                    // The descrption exceeds the maximum description length.

                    await ReplyErrorAsync($"The description length exceeds the maximum allowed length ({maxLength} characters).");
                }
                else
                {
                    await ReplySetTaxonDescriptionAsync(species, sb.ToString());
                }
            }
        }
示例#9
0
        public async Task SetSpeciesDescription(string arg0, string arg1)
        {
            // Possible cases:
            // 1. <genus> <species>
            // 2. <species> <description>

            IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(arg0, arg1);

            if (matchingSpecies.Count() <= 0)
            {
                // We either have case (1) and the species does not exist, or case (2).

                ISpecies species = await GetSpeciesOrReplyAsync(string.Empty, arg0);

                if (species.IsValid())
                {
                    // The first argument was a valid species name, so we have case (2).

                    await ReplySetTaxonDescriptionAsync(species, arg1);
                }
            }
            else
            {
                ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies);

                if (species.IsValid())
                {
                    // We have case (1).

                    await ReplySetTaxonDescriptionAsync(species);
                }
            }
        }
示例#10
0
        public async Task SetTaxonDescription(string taxonName)
        {
            IEnumerable <ITaxon> taxa = await Db.GetTaxaAsync(taxonName);

            if (taxa.Count() <= 0)
            {
                // We did not get any matching taxa.
                // In this case, show species suggestions.

                // If there is no such taxon, default to showing species suggestions.

                ISpecies species = await ReplySpeciesSuggestionAsync(string.Empty, taxonName);

                if (species.IsValid())
                {
                    await ReplySetTaxonDescriptionAsync(species);
                }
            }
            else
            {
                // We got one or more matching taxa.

                ITaxon taxon = await ReplyValidateTaxaAsync(taxa);

                if (taxon.GetRank() == TaxonRankType.Species)
                {
                    taxon = await Db.GetSpeciesAsync(taxon.Id);
                }

                if (taxon.IsValid())
                {
                    await ReplySetTaxonDescriptionAsync(taxon);
                }
            }
        }
示例#11
0
        public async Task SetCommonName(string taxonName, string commonName)
        {
            IEnumerable <ITaxon> taxa = await Db.GetTaxaAsync(taxonName);

            if (taxa.Count() <= 0)
            {
                // We did not get any matching taxa.

                ISpecies species = await ReplySpeciesSuggestionAsync(string.Empty, taxonName);

                if (species.IsValid())
                {
                    await SetSpeciesCommonName(string.Empty, taxonName);
                }
            }
            else
            {
                // We got at least one matching taxon.

                ITaxon taxon = await ReplyValidateTaxaAsync(taxa);

                if (taxon.IsValid())
                {
                    if (taxon.GetRank() == TaxonRankType.Species)
                    {
                        await SetSpeciesCommonName(taxonName, commonName); // species are handled differently
                    }
                    else
                    {
                        await ReplySetTaxonCommonNameAsync(taxon, commonName);
                    }
                }
            }
        }
示例#12
0
        // Privilege replies

        public async Task <bool> ReplyValidatePrivilegeAsync(PrivilegeLevel level, ISpecies species = null)
        {
            if (species.IsValid() && Context.User.Id == species.Creator?.UserId)
            {
                return(true);
            }

            if (Config.HasPrivilegeLevel(Context.User, level))
            {
                return(true);
            }

            string privilegeName = "";

            switch (level)
            {
            case PrivilegeLevel.BotAdmin:
                privilegeName = "Bot Admin";
                break;

            case PrivilegeLevel.ServerAdmin:
                privilegeName = "Admin";
                break;

            case PrivilegeLevel.ServerModerator:
                privilegeName = "Moderator";
                break;
            }

            await ReplyErrorAsync($"You must have {privilegeName.ToTitle().ToBold()} privileges to use this command.");

            return(false);
        }
示例#13
0
        public async Task Gallery([Remainder] string arg0)
        {
            arg0 = StringUtilities.StripOuterQuotes(arg0);

            // Possible cases:
            // 1. <species>
            // 2. <taxon>

            // Prioritize species galleries first.

            IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(arg0);

            if (matchingSpecies.Count() <= 0)
            {
                // No such species exists, so check if a taxon exists.

                ITaxon taxon = (await Db.GetTaxaAsync(arg0)).FirstOrDefault();

                if (!taxon.IsValid())
                {
                    // If no such taxon exists, show species recommendations to the user.

                    ISpecies species = await ReplySpeciesSuggestionAsync(string.Empty, arg0);

                    if (species.IsValid())
                    {
                        await ShowGalleryAsync(species);
                    }
                }
                else
                {
                    // The taxon does exist, so we'll generate a gallery from this taxon.
                    // First, images for this taxon will be added, followed by the galleries for all species under it.

                    List <IPicture> pictures = new List <IPicture>();

                    pictures.AddRange(taxon.Pictures);

                    foreach (ISpecies species in await Db.GetSpeciesAsync(taxon))
                    {
                        pictures.AddRange(await Db.GetPicturesAsync(species));
                    }

                    await ReplyGalleryAsync(taxon.GetName(), pictures);
                }
            }
            else
            {
                // We got one or more matching species.

                ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies);

                if (species.IsValid())
                {
                    await ShowGalleryAsync(species);
                }
            }
        }
示例#14
0
        public async Task Gallery(string genusName, string speciesName)
        {
            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                await ShowGalleryAsync(species);
            }
        }
示例#15
0
        public async Task AppendDescription(string genusName, string speciesName, string description)
        {
            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                await ReplyAppendDescriptionAsync(species, description);
            }
        }
示例#16
0
        public async Task Roles(string genusName, string speciesName)
        {
            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                await ReplyRolesAsync(species);
            }
        }
示例#17
0
        public async Task Roles(string arg0)
        {
            // Possible cases:
            // 1. <role>
            // 2. <species>

            // If a role with this name exists, that's what we'll prioritize (users can use the genus + species overload if they need to).
            // If no such role exists, check for a species with this name instead.

            Common.Roles.IRole role = await Db.GetRoleAsync(arg0);

            if (role.IsValid())
            {
                // The role is valid.
                // List all extant species with this role.

                IEnumerable <ISpecies> species = (await Db.GetSpeciesAsync(role))
                                                 .Where(s => !s.IsExtinct())
                                                 .OrderBy(s => s.GetShortName());

                IEnumerable <Discord.Messaging.IEmbed> pages =
                    EmbedUtilities.CreateEmbedPages($"Extant species with this role ({species.Count()}):", species, options: EmbedPaginationOptions.AddPageNumbers);

                foreach (Discord.Messaging.IEmbed page in pages)
                {
                    page.Title       = $"Role: {role.GetName()}";
                    page.Description = role.GetDescriptionOrDefault();
                }

                await ReplyAsync(new Discord.Messaging.PaginatedMessage(pages));
            }
            else
            {
                // The role is not valid.

                IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(string.Empty, arg0);

                if (matchingSpecies.Count() > 0)
                {
                    ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies);

                    if (species.IsValid())
                    {
                        await ReplyRolesAsync(matchingSpecies.First());
                    }
                }
                else
                {
                    // There were no matching species, so just say that the role is invalid.

                    await this.ReplyValidateRoleAsync(role);
                }
            }
        }
        public async Task MinusRelationship(string genus1, string species1, string genus2, string species2, string relationship)
        {
            // Get the relationship from the DB.

            Relationship relation = await GetRelationshipFromDbAsync(relationship);

            if (!await ReplyValidateRelationshipAsync(Context, relation))
            {
                return;
            }

            // Get the species from the DB.

            ISpecies sp1 = await GetSpeciesOrReplyAsync(genus1, species1);

            if (!sp1.IsValid())
            {
                return;
            }

            ISpecies sp2 = await GetSpeciesOrReplyAsync(genus2, species2);

            if (!sp2.IsValid())
            {
                return;
            }

            // Check if the requested relationship exists.

            using (SQLiteCommand cmd = new SQLiteCommand("SELECT COUNT(*) FROM SpeciesRelationships WHERE (species1_id=$species1_id OR species1_id=$species2_id OR species2_id=$species1_id OR species2_id=$species2_id) AND relationship_id=$relationship_id;")) {
                cmd.Parameters.AddWithValue("$species1_id", sp1.Id);
                cmd.Parameters.AddWithValue("$species2_id", sp2.Id);
                cmd.Parameters.AddWithValue("$relationship_id", relation.id);

                if (await Db.GetScalarAsync <long>(cmd) <= 0)
                {
                    await BotUtils.ReplyAsync_Error(Context, string.Format("No such relationship exists between **{0}** and **{1}**.", sp1.GetShortName(), sp2.GetShortName()));

                    return;
                }
            }

            // Delete the relationship.

            using (SQLiteCommand cmd = new SQLiteCommand("DELETE FROM SpeciesRelationships WHERE (species1_id=$species1_id OR species1_id=$species2_id OR species2_id=$species1_id OR species2_id=$species2_id) AND relationship_id=$relationship_id;")) {
                cmd.Parameters.AddWithValue("$species1_id", sp1.Id);
                cmd.Parameters.AddWithValue("$species2_id", sp2.Id);
                cmd.Parameters.AddWithValue("$relationship_id", relation.id);

                await Db.ExecuteNonQueryAsync(cmd);
            }

            await BotUtils.ReplyAsync_Success(Context, string.Format("**{0}** and **{1}** no longer have a {2} relationship.", sp1.GetShortName(), sp2.GetShortName(), relation.DescriptorName()));
        }
示例#19
0
        public async Task Get(string genusName, string speciesName)
        {
            // Get the species that the user specified.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                await GetGotchiAsync(species);
            }
        }
示例#20
0
        private async Task ReplyAppendDescriptionAsync(ISpecies species)
        {
            if (species.IsValid())
            {
                IMessage message = new Message($"Reply with the description for {species.GetRank().GetName()} **{species.GetFullName()}**.");
                IResponsiveMessageResponse response = await ResponsiveMessageService.GetResponseAsync(Context, message);

                if (!response.Canceled)
                {
                    await ReplyAppendDescriptionAsync(species, await GetDescriptionFromMessageAsync(response.Message));
                }
            }
        }
        public async Task PlusRelationship(string genus1, string species1, string genus2, string species2, string relationship)
        {
            // Get the relationship from the DB.

            Relationship relation = await GetRelationshipFromDbAsync(relationship);

            if (!await ReplyValidateRelationshipAsync(Context, relation))
            {
                return;
            }

            // Get the species from the DB.

            ISpecies sp1 = await GetSpeciesOrReplyAsync(genus1, species1);

            if (!sp1.IsValid())
            {
                return;
            }

            ISpecies sp2 = await GetSpeciesOrReplyAsync(genus2, species2);

            if (!sp2.IsValid())
            {
                return;
            }

            if (sp1.Id == sp2.Id)
            {
                await BotUtils.ReplyAsync_Warning(Context, "A species cannot be in a relationship with itself.");

                return;
            }

            // Create the new relationship.

            using (SQLiteCommand cmd = new SQLiteCommand("INSERT OR REPLACE INTO SpeciesRelationships(species1_id, species2_id, relationship_id) VALUES($species1_id, $species2_id, $relationship_id)")) {
                cmd.Parameters.AddWithValue("$species1_id", sp1.Id);
                cmd.Parameters.AddWithValue("$species2_id", sp2.Id);
                cmd.Parameters.AddWithValue("$relationship_id", relation.id);

                await Db.ExecuteNonQueryAsync(cmd);
            }

            await BotUtils.ReplyAsync_Success(Context, string.Format("**{0}** has successfully been set as a {1} of **{2}**.",
                                                                     sp2.GetShortName(),
                                                                     relation.BeneficiaryName(),
                                                                     sp1.GetShortName()));
        }
示例#22
0
        public async Task SetTaxonDescription(string arg0, string arg1)
        {
            // Possible cases:
            // 1. <taxon> <description>
            // 2. <genus> <species>

            IEnumerable <ISpecies> matchingSpecies = await Db.GetSpeciesAsync(arg0, arg1);

            if (matchingSpecies.Count() <= 0)
            {
                // No such species exists, so we have case (1). Note that this might still be a species (<species> <description>).

                IEnumerable <ITaxon> taxa = await Db.GetTaxaAsync(arg0);

                if (taxa.Count() <= 0)
                {
                    // If there are no matching taxa, show species suggestions.

                    ISpecies species = await ReplySpeciesSuggestionAsync(string.Empty, arg0);

                    if (species.IsValid())
                    {
                        await ReplySetTaxonDescriptionAsync(species, arg1);
                    }
                }
                else
                {
                    // There is at least one matching taxon.

                    ITaxon taxon = await ReplyValidateTaxaAsync(taxa);

                    if (taxon.IsValid())
                    {
                        await ReplySetTaxonDescriptionAsync(taxon, arg1);
                    }
                }
            }
            else
            {
                // There is at least one matching species.

                ISpecies species = await ReplyValidateSpeciesAsync(matchingSpecies);

                if (species.IsValid())
                {
                    await ReplySetTaxonDescriptionAsync(species);
                }
            }
        }
示例#23
0
        public async Task Prey([Remainder] string speciesName)
        {
            speciesName = StringUtilities.StripOuterQuotes(speciesName);

            ISpecies species = await GetSpeciesOrReplyAsync(speciesName);

            if (species.IsValid())
            {
                // Get the preyed-upon species.

                IEnumerable <IPredationInfo> preySpecies = (await Db.GetPreyAsync(species))
                                                           .OrderBy(info => info.Species.GetShortName());

                if (preySpecies.Count() > 0)
                {
                    List <string> lines = new List <string>();

                    foreach (IPredationInfo preyInfo in preySpecies)
                    {
                        string line = TaxonFormatter.GetString(preyInfo.Species);

                        if (!string.IsNullOrEmpty(preyInfo.Notes))
                        {
                            line += (string.Format(" ({0})", preyInfo.Notes.ToLowerInvariant()));
                        }

                        lines.Add(line);
                    }

                    string title = string.Format("Species preyed upon by {0} ({1})", TaxonFormatter.GetString(species, false), preySpecies.Count());

                    IEnumerable <Discord.Messaging.IEmbed> pages = EmbedUtilities.CreateEmbedPages(string.Empty, lines, columnsPerPage: 2, options: EmbedPaginationOptions.AddPageNumbers);

                    Discord.Messaging.IPaginatedMessage message = new Discord.Messaging.PaginatedMessage(pages);

                    message.SetTitle(title);

                    await ReplyAsync(message);
                }
                else
                {
                    await ReplyInfoAsync(string.Format("**{0}** does not prey upon any other species.", species.GetShortName()));
                }
            }
        }
示例#24
0
        public async Task Stats()
        {
            // Get this user's gotchi.

            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (await this.ReplyValidateGotchiAsync(gotchi))
            {
                ISpecies sp = await Db.GetSpeciesAsync(gotchi.SpeciesId);

                if (sp.IsValid())
                {
                    // Calculate stats for this gotchi.
                    // If the user is currently in battle, show their battle stats instead.

                    GotchiStats stats;

                    GotchiBattleState battle_state = GotchiBattleState.GetBattleStateByUserId(Context.User.Id);

                    if (!(battle_state is null))
                    {
                        stats = battle_state.GetGotchiStats(gotchi);
                    }
                    else
                    {
                        stats = await new GotchiStatsCalculator(Db, Global.GotchiContext).GetStatsAsync(gotchi);
                    }

                    // Create the embed.

                    EmbedBuilder stats_page = new EmbedBuilder();

                    stats_page.WithTitle(string.Format("{0}'s {2}, **Level {1}** (Age {3})", Context.User.Username, stats.Level, TaxonFormatter.GetString(sp, false), gotchi.Age));
                    stats_page.WithThumbnailUrl(sp.GetPictureUrl());
                    stats_page.WithFooter(string.Format("{0} experience points until next level", stats.ExperienceToNextLevel));

                    stats_page.AddField("❤ Hit points", stats.Hp, inline: true);
                    stats_page.AddField("💥 Attack", stats.Atk, inline: true);
                    stats_page.AddField("🛡 Defense", stats.Def, inline: true);
                    stats_page.AddField("💨 Speed", stats.Spd, inline: true);

                    await ReplyAsync(embed : stats_page.Build());
                }
            }
示例#25
0
        public async Task PlusPic(string genusName, string speciesName, string imageUrl, string description)
        {
            // Get the species.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid() && await ReplyValidateImageUrlAsync(imageUrl))
            {
                // Add the new picture to the gallery.

                // If this is the first picture we've added to the species, set the artist as the species' owner.
                // Otherwise, set the artist to the person submitting the image.

                IPictureGallery gallery = await Db.GetGalleryAsync(species) ?? new PictureGallery();

                bool isFirstPicture       = gallery.Count() <= 0;
                bool pictureAlreadyExists = gallery
                                            .Any(x => x.Url == imageUrl);

                IPicture picture = gallery
                                   .Where(p => p.Url == imageUrl)
                                   .FirstOrDefault() ?? new Picture();

                picture.Url         = imageUrl;
                picture.Description = description;

                if (string.IsNullOrEmpty(picture.Artist?.Name))
                {
                    picture.Artist = isFirstPicture ? species.Creator : Context.User.ToCreator();
                }

                await Db.AddPictureAsync(species, picture);

                if (pictureAlreadyExists)
                {
                    await ReplySuccessAsync($"Successfully updated {imageUrl.ToLink("picture")} for {species.GetShortName().ToBold()}.");
                }
                else
                {
                    await ReplySuccessAsync($"Successfully added new {imageUrl.ToLink("picture")} for {species.GetShortName().ToBold()}.");
                }
            }
        }
示例#26
0
        public async Task Predates([Remainder] string speciesName)
        {
            speciesName = StringUtilities.StripOuterQuotes(speciesName);

            ISpecies species = await GetSpeciesOrReplyAsync(speciesName);

            if (species.IsValid())
            {
                IEnumerable <IPredationInfo> predatorSpecies = (await Db.GetPredatorsAsync(species))
                                                               .Where(info => !info.Species.IsExtinct())
                                                               .OrderBy(info => info.Species.GetShortName());

                if (predatorSpecies.Count() > 0)
                {
                    Discord.Messaging.IEmbed embed = new Discord.Messaging.Embed();

                    List <string> lines = new List <string>();

                    foreach (IPredationInfo info in predatorSpecies)
                    {
                        string lineText = TaxonFormatter.GetString(info.Species);

                        if (!string.IsNullOrEmpty(info.Notes))
                        {
                            lineText += string.Format(" ({0})", info.Notes.ToLowerInvariant());
                        }

                        lines.Add(lineText);
                    }

                    embed.Title       = string.Format("Predators of {0} ({1})", TaxonFormatter.GetString(species, false), lines.Count());
                    embed.Description = string.Join(Environment.NewLine, lines);

                    await ReplyAsync(embed);
                }
                else
                {
                    await ReplyInfoAsync(string.Format("**{0}** has no extant natural predators.", species.GetShortName()));
                }
            }
        }
示例#27
0
        public async Task RemoveRole(string genusName, string speciesName, string roleName)
        {
            // Get the species.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                // Get the role.

                Common.Roles.IRole role = await Db.GetRoleAsync(roleName);

                if (await this.ReplyValidateRoleAsync(role))
                {
                    // Update the species.

                    await Db.RemoveRoleAsync(species, role);

                    await ReplySuccessAsync($"Role {role.GetName().ToBold()} has successfully been unassigned from {species.GetShortName().ToBold()}.");
                }
            }
        }
示例#28
0
        public async Task AddFav(string genus, string species)
        {
            // Get the requested species.

            ISpecies sp = await GetSpeciesOrReplyAsync(genus, species);

            if (!sp.IsValid())
            {
                return;
            }

            // Add this species to the user's favorites list.

            using (SQLiteCommand cmd = new SQLiteCommand("INSERT OR IGNORE INTO Favorites(user_id, species_id) VALUES($user_id, $species_id);")) {
                cmd.Parameters.AddWithValue("$user_id", Context.User.Id);
                cmd.Parameters.AddWithValue("$species_id", sp.Id);

                await Db.ExecuteNonQueryAsync(cmd);
            }

            await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully added **{0}** to **{1}**'s favorites list.", sp.GetShortName(), Context.User.Username));
        }
示例#29
0
        public async Task MinusFav(string genus, string species)
        {
            // Get the requested species.

            ISpecies sp = await GetSpeciesOrReplyAsync(genus, species);

            if (!sp.IsValid())
            {
                return;
            }

            // Remove this species from the user's favorites list.

            using (SQLiteCommand cmd = new SQLiteCommand("DELETE FROM Favorites WHERE user_id = $user_id AND species_id = $species_id;")) {
                cmd.Parameters.AddWithValue("$user_id", Context.User.Id);
                cmd.Parameters.AddWithValue("$species_id", sp.Id);

                await Db.ExecuteNonQueryAsync(cmd);
            }

            await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully removed **{0}** from **{1}**'s favorites list.", sp.GetShortName(), Context.User.Username));
        }
示例#30
0
        private async Task ReplyRemovePreyAsync(ISpecies predatorSpecies, ISpecies preySpecies)
        {
            if (predatorSpecies.IsValid() && preySpecies.IsValid())
            {
                IEnumerable <IPredationInfo> existingPrey = await Db.GetPreyAsync(predatorSpecies);

                if (existingPrey.Any(info => info.Species.Id == preySpecies.Id))
                {
                    await Db.RemovePreyAsync(predatorSpecies, preySpecies);

                    await ReplySuccessAsync(string.Format("**{0}** no longer preys upon **{1}**.",
                                                          predatorSpecies.GetShortName(),
                                                          preySpecies.GetShortName()));
                }
                else
                {
                    await ReplyWarningAsync(string.Format("**{0}** does not prey upon **{1}**.",
                                                          predatorSpecies.GetShortName(),
                                                          preySpecies.GetShortName()));
                }
            }
        }