Ejemplo n.º 1
0
        public virtual async Task <ILinkable> GetPostAsync(string content, ImageRating r)
        {
            bool nsfw = false;

            string[] command = content.Split(' ');

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

            switch (r)
            {
            case ImageRating.EXPLICIT:
            {
                tags.Add(Config.ExplicitTag);
                nsfw = true;
            }
            break;

            case ImageRating.QUESTIONABLE:
            {
                tags.Add(Config.QuestionableTag);
                nsfw = true;
            }
            break;

            case ImageRating.SAFE:
            {
                tags.Add(Config.SafeTag);
            }
            break;
            }

            tags.AddRange(command);

            if (nsfw)
            {
                RemoveBannedTerms(Config, tags);
                AddBannedTerms(Config, tags);
            }

            string outputTags = GetTags(tags.ToArray());

            using var c = new HttpClient(Config.QueryKey + outputTags);
            if (Config.NetUseCredentials)
            {
                //c.UseDefaultCredentials = true;
                Config.NetHeaders.ForEach(x => c.Headers.Add(x.Item1, x.Item2));
            }

            var request = await c.GetAsync();

            if (string.IsNullOrWhiteSpace(request.Body))
            {
                throw new DataNotFoundException();
            }

            if (request.Success)
            {
                return(Serialize(request.Body));
            }
            return(default);
        void ReleaseDesignerOutlets()
        {
            if (ImageRating != null)
            {
                ImageRating.Dispose();
                ImageRating = null;
            }

            if (ImageType != null)
            {
                ImageType.Dispose();
                ImageType = null;
            }

            if (LableTripDescription != null)
            {
                LableTripDescription.Dispose();
                LableTripDescription = null;
            }

            if (LableTripName != null)
            {
                LableTripName.Dispose();
                LableTripName = null;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the "Raw" rating Nsfw value, so if either of the ratings are above Safe/Tame
 /// This ignores the ratings that the user sets
 /// </summary>
 /// <param name="rating">ImageRating to be checked for NSFW</param>
 /// <returns></returns>
 public static bool RawRatingIsNsfw(ImageRating rating)
 {
     if (rating == null)
     {
         return(false);
     }
     return(rating.SexualAvg >= 1 || rating.ViolenceAvg >= 1);
 }
Ejemplo n.º 4
0
        public virtual async Task <T> GetPostAsync(string content, ImageRating r)
        {
            bool nsfw = false;

            string[] command = content.Split(' ');

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

            switch (r)
            {
            case ImageRating.EXPLICIT:
            {
                tags.Add(Config.ExplicitTag);
                nsfw = true;
            }
            break;

            case ImageRating.QUESTIONABLE:
            {
                tags.Add(Config.QuestionableTag);
                nsfw = true;
            }
            break;

            case ImageRating.SAFE:
            {
                tags.Add(Config.SafeTag);
            }
            break;
            }
            tags.AddRange(command);

            if (nsfw)
            {
                RemoveBannedTerms(Config, tags);
                AddBannedTerms(Config, tags);
            }

            string outputTags = GetTags(tags.ToArray());

            using (RestClient c = new RestClient(Config.QueryKey + outputTags))
            {
                if (Config.NetUseCredentials)
                {
                    //c.UseDefaultCredentials = true;
                    Config.NetHeaders.ForEach(x => c.Headers.Add(x.Item1, x.Item2));
                }

                var b = await c.GetAsync <List <T> >();

                if (b.Success)
                {
                    if (b.Data.Any())
                    {
                        return(b.Data[MikiRandom.Next(0, b.Data.Count)]);
                    }
                }
                return(default);
Ejemplo n.º 5
0
        public static E621Post Create(string content, ImageRating r)
        {
            WebClient c = new WebClient();

            c.UseDefaultCredentials = true;
            c.Credentials           = CredentialCache.DefaultCredentials;

            c.Headers.Add("User-Agent: Other");

            byte[]   b;
            string[] command = content.Split(' ');

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

            switch (r)
            {
            case ImageRating.EXPLICIT:
            {
                tags.Add("rating:e");
            }
            break;

            case ImageRating.QUESTIONABLE:
            {
                tags.Add("rating:q");
            }
            break;

            case ImageRating.SAFE:
            {
                tags.Add("rating:s");
            }
            break;
            }
            tags.AddRange(command);
            RemoveBannedTerms(tags);
            AddBannedTerms(tags);

            string outputTags = GetTags(tags.ToArray());

            b = c.DownloadData("http://e621.net/post/index.json?limit=1&tags=" + outputTags);

            if (b != null)
            {
                string          result = Encoding.UTF8.GetString(b);
                List <E621Post> d      = JsonConvert.DeserializeObject <List <E621Post> >(result);
                if (d != null)
                {
                    return(d[Global.random.Next(0, d.Count)]);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        public static SafebooruPost Create(string content, ImageRating r)
        {
            WebClient c = new WebClient();

            byte[]   b;
            string[] command = content.Split(' ');

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

            switch (r)
            {
            case ImageRating.EXPLICIT:
            {
                tags.Add("rating:explicit");
            }
            break;

            case ImageRating.QUESTIONABLE:
            {
                tags.Add("rating:questionable");
            }
            break;

            case ImageRating.SAFE:
            {
                tags.Add("rating:safe");
            }
            break;
            }

            tags.AddRange(command);
            RemoveBannedTerms(tags);
            AddBannedTerms(tags);

            string outputTags = GetTags(tags.ToArray());

            b = c.DownloadData($"https://safebooru.org/index.php?page=dapi&s=post&q=index&json=1&tags={ outputTags }");
            if (b != null)
            {
                string result          = Encoding.UTF8.GetString(b);
                List <SafebooruPost> d = JsonConvert.DeserializeObject <List <SafebooruPost> >(result);
                if (d != null)
                {
                    return(d[Global.random.Next(0, d.Count)]);
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        public static KonachanPost Create(string content, ImageRating r)
        {
            WebClient c = new WebClient();

            byte[]   b;
            string[] command = content.Split(' ');

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

            switch (r)
            {
            case ImageRating.EXPLICIT:
            {
                tags.Add("rating:e");
            }
            break;

            case ImageRating.QUESTIONABLE:
            {
                tags.Add("rating:q");
            }
            break;

            case ImageRating.SAFE:
            {
                tags.Add("rating:s");
            }
            break;
            }

            tags.AddRange(command);
            RemoveBannedTerms(tags);
            AddBannedTerms(tags);

            string outputTags = GetTags(tags.ToArray());

            b = c.DownloadData($"https://konachan.com/post.json?tags={outputTags}");
            if (b != null)
            {
                string result         = Encoding.UTF8.GetString(b);
                List <KonachanPost> d = JsonConvert.DeserializeObject <List <KonachanPost> >(result);
                if (d != null)
                {
                    return(d[Global.random.Next(0, d.Count)]);
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        void ReleaseDesignerOutlets()
        {
            if (ImageRating != null)
            {
                ImageRating.Dispose();
                ImageRating = null;
            }

            if (LabelInfo != null)
            {
                LabelInfo.Dispose();
                LabelInfo = null;
            }

            if (Map != null)
            {
                Map.Dispose();
                Map = null;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks if the specified rating should be marked NSFW
        /// If either the Sexual or Violence ratings is above the max set by the user, it will be marked NSFW(returns true)
        /// </summary>
        /// <param name="rating">ImageRating to be checked for NSFW</param>
        /// <returns></returns>
        public static bool UserIsNsfw(ImageRating rating)
        {
            if (rating == null)
            {
                return(false);
            }
            var isSexualNsfwValid   = false;
            var isViolenceNsfwValid = false;

            if (rating.SexualAvg != null && rating.SexualAvg >= Convert.ToDouble(SexualRating.Suggestive, CultureInfo.InvariantCulture) &&
                rating.SexualAvg > Convert.ToDouble(App.UserSettings.MaxSexualRating, CultureInfo.InvariantCulture))
            {
                isSexualNsfwValid = true;
            }

            if (rating.ViolenceAvg != null && rating.ViolenceAvg >= Convert.ToDouble(ViolenceRating.Violent, CultureInfo.InvariantCulture) &&
                rating.ViolenceAvg > Convert.ToDouble(App.UserSettings.MaxViolenceRating, CultureInfo.InvariantCulture))
            {
                isViolenceNsfwValid = true;
            }
            //if either is true, mark item as a NSFW item
            return(isSexualNsfwValid || isViolenceNsfwValid);
        }