コード例 #1
0
        public async Task SetPic(string genusName, string speciesName, string imageUrl)
        {
            // Updates the default picture for the given species.
            // While any users can add pictures for species, only moderators can update the default picture.

            Species species = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName);

            if (species is null)
            {
                return;
            }

            if (await BotUtils.ReplyHasPrivilegeOrOwnershipAsync(Context, PrivilegeLevel.ServerModerator, species) && await BotUtils.ReplyIsImageUrlValidAsync(Context, imageUrl))
            {
                Picture[] pictures = await GalleryUtils.GetPicturesAsync(await GalleryUtils.GetGalleryAsync(species));

                bool first_picture = pictures.Count() <= 0;

                await SpeciesUtils.SetPictureAsync(species, new Picture {
                    url    = imageUrl,
                    artist = first_picture ? species.OwnerName : Context.User.Username
                });

                await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully set the picture for **{0}**.", species.ShortName));
            }
        }
コード例 #2
0
        public async Task PlusPic(string genusName, string speciesName, string imageUrl, string description)
        {
            // Get the species.

            Species species = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName);

            if (species is null)
            {
                return;
            }

            // Validate the image URL.

            if (!await BotUtils.ReplyIsImageUrlValidAsync(Context, imageUrl))
            {
                return;
            }

            // 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.

            Picture[] pictures = await GalleryUtils.GetPicturesAsync(await GalleryUtils.GetGalleryAsync(species));

            bool firstPicture         = pictures.Count() <= 0;
            bool pictureAlreadyExists = pictures.Any(x => x.url == imageUrl);

            Picture picture = pictures.Where(x => x.url == imageUrl).FirstOrDefault() ?? new Picture();

            picture.url         = imageUrl;
            picture.description = description;

            if (string.IsNullOrEmpty(picture.artist))
            {
                picture.artist = firstPicture ? species.OwnerName : Context.User.Username;
            }

            await SpeciesUtils.AddPictureAsync(species, picture);

            if (pictureAlreadyExists)
            {
                await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully updated [picture]({1}) for **{0}**.", species.ShortName, imageUrl));
            }
            else
            {
                await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully added new [picture]({1}) for **{0}**.", species.ShortName, imageUrl));
            }
        }