Ejemplo n.º 1
0
 public SubredditSettings(Reddit reddit, Subreddit subreddit, IWebAgent webAgent)
 {
     Subreddit = subreddit;
     Reddit    = reddit;
     WebAgent  = webAgent;
     // Default settings, for use when reduced information is given
     AllowAsDefault    = true;
     AllowImages       = false;
     Domain            = null;
     Sidebar           = string.Empty;
     Language          = "en";
     Title             = Subreddit.DisplayName;
     WikiEditKarma     = 100;
     WikiEditAge       = 10;
     UseDomainCss      = false;
     UseDomainSidebar  = false;
     HeaderHoverText   = string.Empty;
     NSFW              = false;
     PublicDescription = string.Empty;
     WikiEditMode      = WikiEditMode.None;
     SubredditType     = SubredditType.Public;
     ShowThumbnails    = true;
     ContentOptions    = ContentOptions.All;
     SpamFilter        = new SpamFilterSettings();
 }
Ejemplo n.º 2
0
 public SubredditSettings(Reddit reddit, Subreddit subreddit, IWebAgent webAgent)
 {
     Subreddit = subreddit;
     Reddit = reddit;
     WebAgent = webAgent;
     // Default settings, for use when reduced information is given
     AllowAsDefault = true;
     Domain = null;
     Sidebar = string.Empty;
     Language = "en";
     Title = Subreddit.DisplayName;
     WikiEditKarma = 100;
     WikiEditAge = 10;
     UseDomainCss = false;
     UseDomainSidebar = false;
     HeaderHoverText = string.Empty;
     NSFW = false;
     PublicDescription = string.Empty;
     WikiEditMode = WikiEditMode.None;
     SubredditType = SubredditType.Public;
     ShowThumbnails = true;
     ContentOptions = ContentOptions.All;
     SpamFilter = new SpamFilterSettings();
 }
        /// <summary>
        /// Get the subreddit settings page.
        /// </summary>
        /// <param name="subreddit">A subreddit.</param>
        /// <param name="json"></param>
        public SubredditSettings(Subreddit subreddit, JToken json) : this(subreddit)
        {
            var data = json["data"];
            AllowAsDefault    = data["default_set"].ValueOrDefault <bool>();
            AllowImages       = data["allow_images"].ValueOrDefault <bool>();
            Domain            = data["domain"].ValueOrDefault <string>();
            Sidebar           = WebUtility.HtmlDecode(data["description"].ValueOrDefault <string>() ?? string.Empty);
            Language          = data["language"].ValueOrDefault <string>();
            Title             = data["title"].ValueOrDefault <string>();
            WikiEditKarma     = data["wiki_edit_karma"].ValueOrDefault <int>();
            UseDomainCss      = data["domain_css"].ValueOrDefault <bool>();
            UseDomainSidebar  = data["domain_sidebar"].ValueOrDefault <bool>();
            HeaderHoverText   = data["header_hover_text"].ValueOrDefault <string>();
            NSFW              = data["over18"].ValueOrDefault <bool>();
            PublicDescription = WebUtility.HtmlDecode(data["public_description"].ValueOrDefault <string>() ?? string.Empty);
            SpamFilter        = new SpamFilterSettings
            {
                LinkPostStrength = GetSpamFilterStrength(data["spam_links"].ValueOrDefault <string>()),
                SelfPostStrength = GetSpamFilterStrength(data["spam_selfposts"].ValueOrDefault <string>()),
                CommentStrength  = GetSpamFilterStrength(data["spam_comments"].ValueOrDefault <string>())
            };
            if (data["wikimode"] != null)
            {
                var wikiMode = data["wikimode"].ValueOrDefault <string>();
                switch (wikiMode)
                {
                case "disabled":
                    WikiEditMode = WikiEditMode.None;
                    break;

                case "modonly":
                    WikiEditMode = WikiEditMode.Moderators;
                    break;

                case "anyone":
                    WikiEditMode = WikiEditMode.All;
                    break;
                }
            }
            if (data["subreddit_type"] != null)
            {
                var type = data["subreddit_type"].ValueOrDefault <string>();
                switch (type)
                {
                case "public":
                    SubredditType = SubredditType.Public;
                    break;

                case "private":
                    SubredditType = SubredditType.Private;
                    break;

                case "restricted":
                    SubredditType = SubredditType.Restricted;
                    break;
                }
            }
            ShowThumbnails = data["show_media"].ValueOrDefault <bool>();
            WikiEditAge    = data["wiki_edit_age"].ValueOrDefault <int>();
            if (data["content_options"] != null)
            {
                var contentOptions = data["content_options"].ValueOrDefault <string>();
                switch (contentOptions)
                {
                case "any":
                    ContentOptions = ContentOptions.All;
                    break;

                case "link":
                    ContentOptions = ContentOptions.LinkOnly;
                    break;

                case "self":
                    ContentOptions = ContentOptions.SelfOnly;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 public SubredditSettings(Subreddit subreddit, Reddit reddit, JObject json, IWebAgent webAgent) : this(reddit, subreddit, webAgent)
 {
     var data = json["data"];
     AllowAsDefault = data["default_set"].ValueOrDefault<bool>();
     Domain = data["domain"].ValueOrDefault<string>();
     Sidebar = HttpUtility.HtmlDecode(data["description"].ValueOrDefault<string>() ?? string.Empty);
     Language = data["language"].ValueOrDefault<string>();
     Title = data["title"].ValueOrDefault<string>();
     WikiEditKarma = data["wiki_edit_karma"].ValueOrDefault<int>();
     UseDomainCss = data["domain_css"].ValueOrDefault<bool>();
     UseDomainSidebar = data["domain_sidebar"].ValueOrDefault<bool>();
     HeaderHoverText = data["header_hover_text"].ValueOrDefault<string>();
     NSFW = data["over_18"].ValueOrDefault<bool>();
     PublicDescription = HttpUtility.HtmlDecode(data["public_description"].ValueOrDefault<string>() ?? string.Empty);
     SpamFilter = new SpamFilterSettings
     {
         LinkPostStrength = GetSpamFilterStrength(data["spam_links"].ValueOrDefault<string>()),
         SelfPostStrength = GetSpamFilterStrength(data["spam_selfposts"].ValueOrDefault<string>()),
         CommentStrength = GetSpamFilterStrength(data["spam_comments"].ValueOrDefault<string>())
     };
     if (data["wikimode"] != null)
     {
         var wikiMode = data["wikimode"].ValueOrDefault<string>();
         switch (wikiMode)
         {
             case "disabled":
                 WikiEditMode = WikiEditMode.None;
                 break;
             case "modonly":
                 WikiEditMode = WikiEditMode.Moderators;
                 break;
             case "anyone":
                 WikiEditMode = WikiEditMode.All;
                 break;
         }
     }
     if (data["subreddit_type"] != null)
     {
         var type = data["subreddit_type"].ValueOrDefault<string>();
         switch (type)
         {
             case "public":
                 SubredditType = SubredditType.Public;
                 break;
             case "private":
                 SubredditType = SubredditType.Private;
                 break;
             case "restricted":
                 SubredditType = SubredditType.Restricted;
                 break;
         }
     }
     ShowThumbnails = data["show_media"].ValueOrDefault<bool>();
     WikiEditAge = data["wiki_edit_age"].ValueOrDefault<int>();
     if (data["content_options"] != null)
     {
         var contentOptions = data["content_options"].ValueOrDefault<string>();
         switch (contentOptions)
         {
             case "any":
                 ContentOptions = ContentOptions.All;
                 break;
             case "link":
                 ContentOptions = ContentOptions.LinkOnly;
                 break;
             case "self":
                 ContentOptions = ContentOptions.SelfOnly;
                 break;
         }
     }
 }
Ejemplo n.º 5
0
        public SubredditSettings(Subreddit subreddit, Reddit reddit, JObject json, IWebAgent webAgent) : this(reddit, subreddit, webAgent)
        {
            var data = json["data"];

            AllowAsDefault          = data["default_set"].ValueOrDefault <bool>();
            Domain                  = data["domain"].ValueOrDefault <string>();
            Sidebar                 = HttpUtility.HtmlDecode(data["description"].ValueOrDefault <string>() ?? string.Empty);
            Language                = data["language"].ValueOrDefault <string>();
            Title                   = data["title"].ValueOrDefault <string>();
            SubmitText              = data["submit_text"].ValueOrDefault <string>();
            SubmitLinkLabel         = data["submit_link_label"].ValueOrDefault <string>();
            SubmitTextLabel         = data["submit_text_label"].ValueOrDefault <string>();
            CollapseDeletedComments = data["collapse_deleted_comments"].ValueOrDefault <bool>();
            ExcludeBannedModqueue   = data["exclude_banned_modqueue"].ValueOrDefault <bool>();
            WikiEditKarma           = data["wiki_edit_karma"].ValueOrDefault <int>();
            HideAds                 = data["hide_ads"].ValueOrDefault <bool>();
            IsTrafficPublic         = data["public_traffic"].ValueOrDefault <bool>();
            UseDomainCss            = data["domain_css"].ValueOrDefault <bool>();
            UseDomainSidebar        = data["domain_sidebar"].ValueOrDefault <bool>();
            HeaderHoverText         = data["header_hover_text"].ValueOrDefault <string>();
            NSFW = data["over_18"].ValueOrDefault <bool>();
            PublicDescription = HttpUtility.HtmlDecode(data["public_description"].ValueOrDefault <string>() ?? string.Empty);
            SpamFilter        = new SpamFilterSettings
            {
                LinkPostStrength = GetSpamFilterStrength(data["spam_links"].ValueOrDefault <string>()),
                SelfPostStrength = GetSpamFilterStrength(data["spam_selfposts"].ValueOrDefault <string>()),
                CommentStrength  = GetSpamFilterStrength(data["spam_comments"].ValueOrDefault <string>())
            };
            if (data["wikimode"] != null)
            {
                var wikiMode = data["wikimode"].ValueOrDefault <string>();
                switch (wikiMode)
                {
                case "disabled":
                    WikiEditMode = WikiEditMode.None;
                    break;

                case "modonly":
                    WikiEditMode = WikiEditMode.Moderators;
                    break;

                case "anyone":
                    WikiEditMode = WikiEditMode.All;
                    break;
                }
            }
            if (data["subreddit_type"] != null)
            {
                var type = data["subreddit_type"].ValueOrDefault <string>();
                switch (type)
                {
                case "public":
                    SubredditType = SubredditType.Public;
                    break;

                case "private":
                    SubredditType = SubredditType.Private;
                    break;

                case "restricted":
                    SubredditType = SubredditType.Restricted;
                    break;

                case "gold_restricted":
                    SubredditType = SubredditType.GoldRestricted;
                    break;

                case "archived":
                    SubredditType = SubredditType.Archived;
                    break;

                case "gold_only":
                    SubredditType = SubredditType.GoldOnly;
                    break;

                case "employees_only":
                    SubredditType = SubredditType.EmployeesOnly;
                    break;
                }
            }
            ShowThumbnails             = data["show_media"].ValueOrDefault <bool>();
            ShowMediaPreviews          = data["show_media_preview"].ValueOrDefault <bool>();
            AllowImages                = data["allow_images"].ValueOrDefault <bool>();
            MinutesToHideCommentScores = data["comment_score_hide_mins"].ValueOrDefault <int>();
            WikiEditAge                = data["wiki_edit_age"].ValueOrDefault <int>();
            if (data["content_options"] != null)
            {
                var contentOptions = data["content_options"].ValueOrDefault <string>();
                switch (contentOptions)
                {
                case "any":
                    ContentOptions = ContentOptions.All;
                    break;

                case "link":
                    ContentOptions = ContentOptions.LinkOnly;
                    break;

                case "self":
                    ContentOptions = ContentOptions.SelfOnly;
                    break;
                }
            }
            if (data["suggested_comment_sort"] != null)
            {
                var suggestedCommentSort = data["suggested_comment_sort"].ValueOrDefault <string>();
                switch (suggestedCommentSort)
                {
                case "confidence":
                    SuggestedCommentSort = CommentSorts.Confidence;
                    break;

                case "top":
                    SuggestedCommentSort = CommentSorts.Top;
                    break;

                case "new":
                    SuggestedCommentSort = CommentSorts.New;
                    break;

                case "controversial":
                    SuggestedCommentSort = CommentSorts.Controversial;
                    break;

                case "old":
                    SuggestedCommentSort = CommentSorts.Old;
                    break;

                case "random":
                    SuggestedCommentSort = CommentSorts.Random;
                    break;

                case "qa":
                    SuggestedCommentSort = CommentSorts.Qa;
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the subreddit settings page.
        /// </summary>
        /// <param name="subreddit">A subreddit.</param>
        /// <param name="json"></param>
        public SubredditSettings(Subreddit subreddit, JToken json) : this(subreddit)
        {
            var data = json["data"];
            AllowAsDefault    = data["default_set"].ValueOrDefault <bool>();
            AllowImages       = data["allow_images"].ValueOrDefault <bool>();
            Domain            = data["domain"].ValueOrDefault <string>();
            Sidebar           = WebUtility.HtmlDecode(data["description"].ValueOrDefault <string>() ?? string.Empty);
            Language          = data["language"].ValueOrDefault <string>();
            Title             = data["title"].ValueOrDefault <string>();
            WikiEditKarma     = data["wiki_edit_karma"].ValueOrDefault <int>();
            UseDomainCss      = data["domain_css"].ValueOrDefault <bool>();
            UseDomainSidebar  = data["domain_sidebar"].ValueOrDefault <bool>();
            HeaderHoverText   = data["header_hover_text"].ValueOrDefault <string>();
            NSFW              = data["over18"].ValueOrDefault <bool>();
            PublicDescription = WebUtility.HtmlDecode(data["public_description"].ValueOrDefault <string>() ?? string.Empty);
            SpamFilter        = new SpamFilterSettings
            {
                LinkPostStrength = GetSpamFilterStrength(data["spam_links"].ValueOrDefault <string>()),
                SelfPostStrength = GetSpamFilterStrength(data["spam_selfposts"].ValueOrDefault <string>()),
                CommentStrength  = GetSpamFilterStrength(data["spam_comments"].ValueOrDefault <string>())
            };

            FreeFormReports           = data["free_form_reports"].ValueOrDefault <bool>();
            SubmitText                = WebUtility.HtmlDecode(data["submit_text"].ValueOrDefault <string>() ?? string.Empty);
            CollapseDeletedComments   = data["collapse_deleted_comments"].ValueOrDefault <bool>();
            AllowVideos               = data["allow_videos"].ValueOrDefault <bool>();
            SpoilersEnabled           = data["spoilers_enabled"].ValueOrDefault <bool>();
            OriginalContentTagEnabled = data["original_content_tag_enabled"].ValueOrDefault <bool>();
            SubmitLinkLabel           = data["submit_link_label"].ValueOrDefault <string>();
            AllowPostCrossposts       = data["allow_post_crossposts"].ValueOrDefault <bool>();
            PublicTraffic             = data["public_traffic"].ValueOrDefault <bool>();
            SubmitTextLabel           = data["submit_text_label"].ValueOrDefault <string>();
            AllOriginalContent        = data["all_original_content"].ValueOrDefault <bool>();
            HideAds               = data["hide_ads"].ValueOrDefault <bool>();
            AllowDiscovery        = data["allow_discovery"].ValueOrDefault <bool>();
            ShowMediaPreview      = data["show_media_preview"].ValueOrDefault <bool>();
            CommentScoreHideMins  = data["comment_score_hide_mins"].ValueOrDefault <int>();
            ExcludeBannedModqueue = data["exclude_banned_modqueue"].ValueOrDefault <bool>();

            if (data["suggested_comment_sort"] != null)
            {
                // one of (confidence, top, new, controversial, old, random, qa, live)
                var suggestedCommentSort = data["suggested_comment_sort"].ValueOrDefault <string>();

                if (!string.IsNullOrEmpty(suggestedCommentSort))
                {
                    switch (suggestedCommentSort)
                    {
                    case "confidence":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Confidence;
                        break;

                    case "top":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Top;
                        break;

                    case "new":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.New;
                        break;

                    case "controversial":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Controversial;
                        break;

                    case "old":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Old;
                        break;

                    case "random":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Random;
                        break;

                    case "qa":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Qa;
                        break;

                    case "live":
                        SuggestedCommentSort = RedditSharp.SuggestedCommentSort.Live;
                        break;
                    }
                }
            }

            if (data["wikimode"] != null)
            {
                var wikiMode = data["wikimode"].ValueOrDefault <string>();
                switch (wikiMode)
                {
                case "disabled":
                    WikiEditMode = WikiEditMode.None;
                    break;

                case "modonly":
                    WikiEditMode = WikiEditMode.Moderators;
                    break;

                case "anyone":
                    WikiEditMode = WikiEditMode.All;
                    break;
                }
            }

            if (data["subreddit_type"] != null)
            {
                var type = data["subreddit_type"].ValueOrDefault <string>();
                switch (type)
                {
                case "public":
                    SubredditType = SubredditType.Public;
                    break;

                case "private":
                    SubredditType = SubredditType.Private;
                    break;

                case "restricted":
                    SubredditType = SubredditType.Restricted;
                    break;
                }
            }

            ShowThumbnails = data["show_media"].ValueOrDefault <bool>();
            WikiEditAge    = data["wiki_edit_age"].ValueOrDefault <int>();

            if (data["content_options"] != null)
            {
                var contentOptions = data["content_options"].ValueOrDefault <string>();
                switch (contentOptions)
                {
                case "any":
                    ContentOptions = ContentOptions.All;
                    break;

                case "link":
                    ContentOptions = ContentOptions.LinkOnly;
                    break;

                case "self":
                    ContentOptions = ContentOptions.SelfOnly;
                    break;
                }
            }
        }