コード例 #1
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task<bool> RemoveFromBanList(int id, string modName ) {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            string entName = await bannedEntDAL.RemoveBannedEntity( id, Subreddit.Name, modName );

            var newList = await bannedEntDAL.GetBannedEntities( Subreddit.Name );
            cache.Set( CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes( 30 ) );

            bool done = false;
            done = string.IsNullOrWhiteSpace( entName );
            int count = 1;
            while ( !done && count < 5 ) {
                try {
                    done = await SaveAutoModConfig( $"{modName} unbanned {entName}" );
                }
                catch ( WebException ex ) {
                    if ( ( ex.Response as HttpWebResponse ).StatusCode == HttpStatusCode.Forbidden ) {
                        throw;
                    }
                    else count++;
                    await Task.Delay( 100 );
                }

            }
            return true;
        }
コード例 #2
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task<bool> AddToBanList( IEnumerable<DirtBag.Models.BannedEntity> entities ) {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            await bannedEntDAL.LogNewBannedEntities( entities );

            var newList = await bannedEntDAL.GetBannedEntities( Subreddit.Name );
            cache.Set( CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes( 30 ) );

            var userEntities = entities.Where( e => e.Type == Models.BannedEntity.EntityType.User );
            string reason = $"Banned {string.Join( ",", userEntities.Select( e => e.EntityString + ":" + e.BanReason ) )} by {string.Join( ",", userEntities.Select( e => e.BannedBy ).Distinct() )}";
            if ( reason.Length > 255 ) reason = $"Banned {string.Join( ",", userEntities.Select( e => e.EntityString ) )} for {string.Join( ",", userEntities.Select( e => e.BanReason ).Distinct() )} by {string.Join( ",", userEntities.Select( e => e.BannedBy ).Distinct() )}";
            if ( reason.Length > 255 ) reason = "Banned lots of things and the summary is too long for the description.. RIP";

            bool done = false;
            //only needs to update config if there was a user added
            done = userEntities.Count() <= 0;
            int count = 1;
            while ( !done && count < 5 ) {
                try {
                    done = await SaveAutoModConfig( reason );
                }
                catch ( WebException ex ) {
                    if ( ( ex.Response as HttpWebResponse ).StatusCode == HttpStatusCode.Forbidden ) {
                        throw;
                    }
                    else count++;
                    await Task.Delay( 100 );
                }

            }

            return true;
        }
コード例 #3
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task <bool> RemoveFromBanList(int id, string modName)
        {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            string             entName      = await bannedEntDAL.RemoveBannedEntity(id, Subreddit.Name, modName);

            var newList = await bannedEntDAL.GetBannedEntities(Subreddit.Name);

            cache.Set(CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes(30));

            bool done = false;

            done = string.IsNullOrWhiteSpace(entName);
            int count = 1;

            while (!done && count < 5)
            {
                try {
                    done = await SaveAutoModConfig($"{modName} unbanned {entName}");
                }
                catch (WebException ex) {
                    if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw;
                    }
                    else
                    {
                        count++;
                    }
                    await Task.Delay(100);
                }
            }
            return(true);
        }
コード例 #4
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task <bool> UpdateBanReason(int id, string subredditName, string modName, string banReason)
        {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            var toReturn = await bannedEntDAL.UpdateBanReason(id, subredditName, modName, banReason);

            var newList = await bannedEntDAL.GetBannedEntities(Subreddit.Name);

            cache.Set(CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes(30));

            return(toReturn);
        }
コード例 #5
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task <IEnumerable <Models.BannedEntity> > GetBannedList()
        {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            var cacheVal = cache[CACHE_PREFIX + Subreddit];

            if (cacheVal == null)
            {
                var newList = await bannedEntDAL.GetBannedEntities(Subreddit.Name);

                cache.Set(CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes(30));
                return(newList);
            }
            return((IEnumerable <Models.BannedEntity>)cacheVal);
        }
コード例 #6
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task <bool> AddToBanList(IEnumerable <DirtBag.Models.BannedEntity> entities)
        {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            await bannedEntDAL.LogNewBannedEntities(entities);

            var newList = await bannedEntDAL.GetBannedEntities(Subreddit.Name);

            cache.Set(CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes(30));

            var    userEntities = entities.Where(e => e.Type == Models.BannedEntity.EntityType.User);
            string reason       = $"Banned {string.Join( ",", userEntities.Select( e => e.EntityString + ":" + e.BanReason ) )} by {string.Join( ",", userEntities.Select( e => e.BannedBy ).Distinct() )}";

            if (reason.Length > 255)
            {
                reason = $"Banned {string.Join( ",", userEntities.Select( e => e.EntityString ) )} for {string.Join( ",", userEntities.Select( e => e.BanReason ).Distinct() )} by {string.Join( ",", userEntities.Select( e => e.BannedBy ).Distinct() )}";
            }
            if (reason.Length > 255)
            {
                reason = "Banned lots of things and the summary is too long for the description.. RIP";
            }

            bool done = false;

            //only needs to update config if there was a user added
            done = userEntities.Count() <= 0;
            int count = 1;

            while (!done && count < 5)
            {
                try {
                    done = await SaveAutoModConfig(reason);
                }
                catch (WebException ex) {
                    if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw;
                    }
                    else
                    {
                        count++;
                    }
                    await Task.Delay(100);
                }
            }

            return(true);
        }
コード例 #7
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
 public async Task<IEnumerable<Models.BannedEntity>> GetBannedList() {
     DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
     var cacheVal = cache[CACHE_PREFIX + Subreddit];
     if ( cacheVal == null ) {
         var newList = await bannedEntDAL.GetBannedEntities( Subreddit.Name );
         cache.Set( CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes( 30 ) );
         return newList;
     }
     return (IEnumerable<Models.BannedEntity>) cacheVal;
 }
コード例 #8
0
ファイル: AutoModWrangler.cs プロジェクト: CrustyJew/DirtBag
        public async Task<bool> UpdateBanReason(int id, string subredditName, string modName, string banReason ) {
            DAL.BannedEntities bannedEntDAL = new DAL.BannedEntities();
            var toReturn = await bannedEntDAL.UpdateBanReason( id, subredditName, modName, banReason );

            var newList = await bannedEntDAL.GetBannedEntities( Subreddit.Name );
            cache.Set( CACHE_PREFIX + Subreddit, newList, DateTimeOffset.Now.AddMinutes( 30 ) );

            return toReturn;
        }