示例#1
0
        public async Task AddToBanListTest() {

            var Agent = new RedditWebAgent();
            RedditWebAgent.EnableRateLimit = true;
            RedditWebAgent.RateLimit = RedditWebAgent.RateLimitMode.Burst;
            RedditWebAgent.RootDomain = "oauth.reddit.com";
            RedditWebAgent.UserAgent = "DirtBagUnitTests (By meepster23)";
            RedditWebAgent.Protocol = "https";
            var Auth = new RedditAuth( Agent );

            Auth.Login();
            Agent.AccessToken = Auth.AccessToken;

            AutoModWrangler w = new AutoModWrangler( new RedditSharp.Reddit( Agent, true ).GetSubreddit( "GooAway" ) );
            await w.AddToBanList( new List<Models.BannedEntity>() { new Models.BannedEntity() { BanDate = DateTime.UtcNow, BannedBy = "DirtBagTests", BanReason = "DirtBagTests", EntityString = "DirtBagTests", Type= Models.BannedEntity.EntityType.User, SubName = "GooAway", ThingID = "66666" } } );

            var list = await w.GetBannedList();
            int id = list.Where( l => l.ThingID == "66666" && l.BannedBy == "DirtBagTests" ).Select(l=>l.ID).First();
            await w.RemoveFromBanList( id, "DirtBagTests" );
        }
示例#2
0
        public static void Initialize() {
            var uAgent = ConfigurationManager.AppSettings["UserAgentString"];
            var sub = ConfigurationManager.AppSettings["Subreddit"];
            if ( string.IsNullOrEmpty( uAgent ) ) throw new Exception( "Provide setting 'UserAgentString' in AppConfig to avoid Reddit throttling!" );
            if ( string.IsNullOrEmpty( sub ) ) throw new Exception( "Provide setting 'Subreddit' in AppConfig" );
            Subreddit = sub;
            Agent = new RedditWebAgent();
            RedditWebAgent.EnableRateLimit = true;
            RedditWebAgent.RateLimit = RedditWebAgent.RateLimitMode.Burst;
            RedditWebAgent.RootDomain = "oauth.reddit.com";
            RedditWebAgent.UserAgent = uAgent;
            RedditWebAgent.Protocol = "https";
            Auth = new RedditAuth( Agent );

            Auth.Login();
            Agent.AccessToken = Auth.AccessToken;
            //BurstDebug = new Timer( CheckBurstStats, Agent, 0, 20000 );
            Client = new Reddit( Agent, true );

            Settings = new BotSettings();
            Settings.OnSettingsModified += Settings_OnSettingsModified;
            Settings.Subreddit = Subreddit;
            Settings.Initialize( Client );

        }