Пример #1
0
        public async Task TestBooruNotSafe()
        {
            var result = await Booru.SearchBooru(false, new string[] { "cum_in_pussy" }, new BooruSharp.Booru.Gelbooru(), new Random());

            Assert.Equal(Error.Booru.None, result.error);
            Assert.Equal(Color.Red, result.answer.colorRating);
            Assert.True(await IsLinkValid(result.answer.url));
        }
Пример #2
0
        public async Task TestBooruSafe()
        {
            var result = await Booru.SearchBooru(false, null, new BooruSharp.Booru.Safebooru(), new Random());

            Assert.Equal(Error.Booru.None, result.error);
            Assert.Equal(Color.Green, result.answer.colorRating);
            Assert.True(await IsLinkValid(result.answer.url));
        }
Пример #3
0
        public async Task TestSourceAnime()
        {
            var result = await Booru.SearchSourceBooru(new[] { "https://katdon.files.wordpress.com/2015/10/gochuumon.png" });

            Assert.Equal(Error.SourceBooru.None, result.error);
            Assert.NotNull(result.answer);
            Assert.True(await IsLinkValid(result.answer.url));
            Assert.InRange(result.answer.compatibility, 80f, 99f);
            Assert.Contains("はたらく細胞", result.answer.content);
        }
Пример #4
0
        public async Task TestSourceBooru()
        {
            var result = await Booru.SearchSourceBooru(new[] { "https://konachan.net/sample/8e62b8cf03665480cfe40e71a9cc8797/Konachan.com%20-%20273621%20sample.jpg" });

            Assert.Equal(Error.SourceBooru.None, result.error);
            Assert.NotNull(result.answer);
            Assert.Equal("https://img3.saucenao.com/booru/8/7/87b29dd1740518f2d0394b8d76e31509_1.jpg", result.answer.url);
            Assert.InRange(result.answer.compatibility, 90f, 99f);
            Assert.Contains("Twitter @Calico_Malyu", result.answer.content);
            Assert.Contains("kantai collection", result.answer.content);
        }
Пример #5
0
        public async Task TestBooruTypo()
        {
            BooruSharp.Booru.Gelbooru booru = new BooruSharp.Booru.Gelbooru();
            Random rand         = new Random();
            var    resultSearch = await Booru.SearchBooru(false, new string[] { "tsutsukakushi_tsuki" }, booru, rand);

            Assert.Equal(Error.Booru.None, resultSearch.error);
            var resultTags = await Booru.SearchTags(new string[] { resultSearch.answer.saveId.ToString() });

            Assert.Equal(Error.BooruTags.None, resultTags.error);
            Assert.Contains("tsutsukakushi_tsukiko", resultTags.answer.characTags);
        }
Пример #6
0
        public static string getBooruUrl(Booru booru, string[] tags)
        {
            int maxVal = booru.getNbMax(getTags(tags));

            if (maxVal <= 0) // TODO: weird parsing sometimes (example hibiki_(kantai_collection) cut in half if not found)
            {
                return(null);
            }
            else
            {
                return(booru.getLink(getTags(tags), maxVal));
            }
        }
Пример #7
0
        public async Task TestBooruTag()
        {
            BooruSharp.Booru.Gelbooru booru = new BooruSharp.Booru.Gelbooru();
            Random rand         = new Random();
            var    resultSearch = await Booru.SearchBooru(false, new string[] { "hibiki_(kantai_collection)" }, booru, rand);

            var resultTags = await Booru.SearchTags(new string[] { resultSearch.answer.saveId.ToString() });

            Assert.Equal(Error.BooruTags.None, resultTags.error);
            Assert.Contains("hibiki_(kantai_collection)", resultTags.answer.characTags);
            Assert.Contains("kantai_collection", resultTags.answer.sourceTags);
            Assert.Equal("Gelbooru", resultTags.answer.booruName);
        }
Пример #8
0
        private static List <string> getTagsInfos(string json, Booru booru)
        {
            List <string> animeFrom = new List <string>();
            List <string> characs   = new List <string>();
            List <string> artists   = new List <string>();

            string[] allTags = booru.getAllTags(json).Split(' ');
            using (WebClient w = new WebClient())
            {
                foreach (string t in allTags)
                {
                    foreach (string s in booru.getTagInfo(t))
                    {
                        if (booru.getTagName(s) == t)
                        {
                            switch (booru.getTagType(s))
                            {
                            case "1":
                                artists.Add(t);
                                break;

                            case "3":
                                animeFrom.Add(t);
                                break;

                            case "4":
                                characs.Add(t);
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            return(writeTagsInfos(animeFrom, characs, artists));
        }
Пример #9
0
#pragma warning restore CS1998

        /// <summary>
        /// Get an image given various informations
        /// </summary>
        /// <param name="booru">Which booru is concerned (see above)</param>
        /// <param name="tags">Tags that need to be contain on the image</param>
        /// <param name="chan">Channel the image will be post in</param>
        /// <param name="currName">Temporary name of the file</param>
        /// <param name="isSfw">Is the channel safe for work ?</param>
        /// <param name="isGame">If the request from Game module (doesn't count dl for stats and don't get informations about tags)</param>
        public static async void getImage(Booru booru, string[] tags, ITextChannel chan, string currName, bool isSfw, bool isGame)
        {
            if (!isSfw && !chan.IsNsfw)
            {
                await chan.SendMessageAsync(Sentences.chanIsNotNsfw(chan.GuildId));

                return;
            }
            IGuildUser me = await chan.Guild.GetUserAsync(Sentences.myId);

            if (!me.GuildPermissions.AttachFiles)
            {
                await chan.SendMessageAsync(Sentences.needAttachFile(chan.GuildId));

                return;
            }
            if (!isGame)
            {
                await chan.SendMessageAsync(Sentences.prepareImage(chan.GuildId));
            }
            string url = getBooruUrl(booru, tags);

            if (url == null)
            {
                await chan.SendMessageAsync(Sentences.tagsNotFound(tags));
            }
            else
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("User-Agent: Sanara");
                    string json      = wc.DownloadString(url);
                    string image     = booru.getFileUrl(json);
                    string imageName = currName + "." + image.Split('.')[image.Split('.').Length - 1];
                    wc.Headers.Add("User-Agent: Sanara");
                    wc.DownloadFile(image, imageName);
                    FileInfo file = new FileInfo(imageName);
                    Program.p.statsMonth[(int)booru.getId()] += file.Length;
                    if (file.Length >= 8000000)
                    {
                        await chan.SendMessageAsync(Sentences.fileTooBig(chan.GuildId));
                    }
                    else
                    {
                        while (true)
                        {
                            try
                            {
                                await chan.SendFileAsync(imageName);

                                break;
                            }
                            catch (RateLimitedException) { }
                        }
                        if (!isGame)
                        {
                            List <string> finalStr = getTagsInfos(json, booru);
                            foreach (string s in finalStr)
                            {
                                await chan.SendMessageAsync(s);
                            }
                        }
                    }
                    File.Delete(imageName);
                }
                if (!isGame)
                {
                    string finalStrModule = "";
                    foreach (long i in Program.p.statsMonth)
                    {
                        finalStrModule += i + "|";
                    }
                    finalStrModule = finalStrModule.Substring(0, finalStrModule.Length - 1);
                    File.WriteAllText("Saves/MonthModules.dat", finalStrModule + Environment.NewLine + Program.p.lastMonthSent);
                }
            }
        }