Exemplo n.º 1
0
 private void CreateWikiPage( Wiki wiki )
 {
     Version = Program.VersionNumber;
     RunEveryXMinutes = 10;
     LastModified = DateTime.UtcNow;
     ReportScoreThreshold = -1;
     RemoveScoreThreshold = -1;
     /*** Module Settings ***/
     LicensingSmasher = new LicensingSmasherSettings();
     YouTubeSpamDetector = new YouTubeSpamDetectorSettings();
     UserStalker = new UserStalkerSettings();
     SelfPromotionCombustor = new SelfPromotionCombustorSettings();
     /*** End Module Settings ***/
     wiki.EditPage( WikiPageName, JsonConvert.SerializeObject( this, Formatting.Indented, new StringEnumConverter()).Replace("\r\n  ","\r\n\r\n    ") );
     wiki.SetPageSettings( WikiPageName, new WikiPageSettings { Listed = false, PermLevel = 2 } );
 }
Exemplo n.º 2
0
 public UserStalker(UserStalkerSettings settings, Reddit reddit, string sub) : this()
 {
     RedditClient = reddit;
     Subreddit    = sub;
     Settings     = settings;
 }
Exemplo n.º 3
0
        public void ReadSettings( Reddit r )
        {
            var wiki = r.GetSubreddit( Subreddit ).Wiki;
            WikiPage settingsPage;
            try {
                settingsPage = wiki.GetPage( WikiPageName );
            }
            catch(WebException ex) {
                if ( ( ex.Response as HttpWebResponse ).StatusCode == HttpStatusCode.NotFound ) {
                    //Page doesn't exist, create it with defaults.
                    CreateWikiPage( wiki );
                    OnSettingsModified?.Invoke( this, EventArgs.Empty );
                    return;
                }
                else if ( ( ex.Response as HttpWebResponse ).StatusCode == HttpStatusCode.Unauthorized){
                    throw new Exception( "Bot needs wiki permissions yo!" );
                }
                else { //todo retry handling?
                    throw;
                }
            }
            if ( string.IsNullOrEmpty( settingsPage.MarkdownContent ) ) {
                CreateWikiPage( wiki );
                OnSettingsModified?.Invoke( this, EventArgs.Empty );
                return;
            }

            if ( settingsPage.RevisionDate != null && settingsPage.RevisionDate.Value > LastModified ) {
                BotSettings sets;
                try {
                    sets = JsonConvert.DeserializeObject<BotSettings>( settingsPage.MarkdownContent );
                }
                catch {
                    throw new Exception( "Wikipage is corrupted. Fix it, clear wiki page, or delete the page to recreate with defaults." );
                }
                Version = sets.Version;
                LastModified = settingsPage.RevisionDate.Value;
                RemoveScoreThreshold = sets.RemoveScoreThreshold;
                ReportScoreThreshold = sets.ReportScoreThreshold;
                RunEveryXMinutes = sets.RunEveryXMinutes;

                var addedDefaults = false;
                /***Module Defaults***/
                if ( sets.LicensingSmasher == null ) {
                    LicensingSmasher = new LicensingSmasherSettings();
                    addedDefaults = true;
                }
                else {
                    LicensingSmasher = sets.LicensingSmasher;
                }
                if (sets.YouTubeSpamDetector == null ) {
                    YouTubeSpamDetector = new YouTubeSpamDetectorSettings();
                    addedDefaults = true;
                }
                else {
                    YouTubeSpamDetector = sets.YouTubeSpamDetector;
                }
                if(sets.UserStalker == null ) {
                    UserStalker = new UserStalkerSettings();
                    addedDefaults = true;
                }
                else {
                    UserStalker = sets.UserStalker;
                }
                if(sets.SelfPromotionCombustor == null ) {
                    SelfPromotionCombustor = new SelfPromotionCombustorSettings();
                    addedDefaults = true;
                }
                else {
                    SelfPromotionCombustor = sets.SelfPromotionCombustor;
                }
                if(sets.HighTechBanHammer == null ) {
                    HighTechBanHammer = new HighTechBanHammerSettings();
                    addedDefaults = true;
                }
                else {
                    HighTechBanHammer = sets.HighTechBanHammer;
                }
                /***End Module Defaults ***/
                if ( addedDefaults ) {
                    wiki.EditPage( WikiPageName, JsonConvert.SerializeObject( this, Formatting.Indented, new StringEnumConverter()).Replace( "\r\n  ", "\r\n\r\n    " ), reason: "Add module default" );
                    LastModified = DateTime.UtcNow.AddMinutes( 1 );
                }
                Console.WriteLine("Settings in wiki changed or read for first time : Revision Date = {0}", LastModified);
                OnSettingsModified?.Invoke( this, EventArgs.Empty );
            }
            else {
                Console.WriteLine( "No updates to settings detected in wiki" );
            }
        }
Exemplo n.º 4
0
 public UserStalker( UserStalkerSettings settings, Reddit reddit, string sub ) : this() {
     RedditClient = reddit;
     Subreddit = sub;
     Settings = settings;
 }