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;
     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(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;
                }
            }
        }