Exemple #1
0
        public async Task <bool> BanUser(Models.BannedEntity user)
        {
            var newBan = await bbDAL.BanUser(new Models.BannedEntity[] { user });

            if (!newBan)
            {
                return(false);
            }

            string reason = $"Banned {user.UserName} : {user.BanReason}";

            //only used if changing to allowing banning of multiple users at a time.
            //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;
            int  count = 1;

            var ident = await userManager.FindByNameAsync(user.BannedBy);

            var webAgent = await agentPool.GetOrCreateWebAgentAsync(user.BannedBy, (uname, uagent, rlimit) =>
            {
                return(Task.FromResult <RedditSharp.RefreshTokenPoolEntry>(new RedditSharp.RefreshTokenPoolEntry(uname, ident.RefreshToken, rlimit, uagent)));
            });

            if (!ident.HasWiki)
            {
                throw new UnauthorizedAccessException("Need Wiki Permissions");
            }
            if (!ident.HasConfig)
            {
                throw new UnauthorizedAccessException("Need Config Permissions");
            }
            RedditSharp.Reddit rd = new RedditSharp.Reddit(webAgent, true);

            var wiki = new RedditSharp.Wiki(webAgent, user.SubName);

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

            return(true);
        }
Exemple #2
0
        public async Task BanChannel(string subName, string url, string reason, string thingID, string bannedBy)
        {
            DAL.YouTubeDAL ytDAL   = new DAL.YouTubeDAL();
            string         ytVidID = Helpers.YouTubeHelpers.ExtractVideoId(url);

            if (string.IsNullOrWhiteSpace(ytVidID))
            {
                throw new ArgumentException($"Couldn't extract YouTube video ID from url: {url}");
            }
            string channelID = await ytDAL.GetChannelID(ytVidID);

            Models.BannedEntity toBan = new Models.BannedEntity()
            {
                BanDate      = DateTime.UtcNow,
                BannedBy     = bannedBy,
                BanReason    = reason,
                EntityString = channelID,
                SubName      = subName,
                ThingID      = thingID,
                Type         = Models.BannedEntity.EntityType.Channel
            };
            var conn = await GetSettings(subName);

            DAL.DirtbagDAL dirtbag = new DAL.DirtbagDAL();
            await dirtbag.AddToBanList(conn, new List <Models.BannedEntity>() { toBan });
        }
Exemple #3
0
        public async Task <bool> BanChannel(Models.BannedEntity channel)
        {
            string vidID   = Helpers.YouTubeHelpers.ExtractVideoId(channel.ChannelURL);
            var    vidInfo = await ytDAL.GetChannelIDAndName(vidID);

            return(await bbDAL.BanChannel(channel, vidInfo.Key, vidInfo.Value, VideoProvider.YouTube)); //TODO support more vid providers
        }
Exemple #4
0
        public Task BanChannel(Models.BannedEntity entity, string subname)
        {
            if (!ClaimsPrincipal.Current.HasClaim($"urn:snoonotes:subreddits:{subname.ToLower()}:admin", "true"))
            {
                throw new UnauthorizedAccessException("You are not an admin of this subreddit!");
            }

            BLL.DirtbagBLL dirtbag = new BLL.DirtbagBLL();
            return(dirtbag.BanChannel(subname, entity.EntityString, entity.BanReason, entity.ThingID, ClaimsPrincipal.Current.Identity.Name));
        }
        public Task <bool> BanUser(string sub, [FromBody] Models.BannedEntity entity)
        {
            ClaimsPrincipal ident = User as ClaimsPrincipal;

            if (!ident.HasClaim("uri:snoonotes:admin", sub.ToLower()))
            {
                throw new UnauthorizedAccessException("Not an admin of that sub");
            }
            entity.SubName  = sub;
            entity.BannedBy = ident.Identity.Name;
            entity.BanDate  = DateTime.UtcNow;
            return(bbBLL.BanUser(entity));
        }
Exemple #6
0
        public async Task BanUser(string subName, string username, string reason, string thingID, string bannedBy)
        {
            Models.BannedEntity toBan = new Models.BannedEntity()
            {
                BanDate      = DateTime.UtcNow,
                BannedBy     = bannedBy,
                BanReason    = reason,
                EntityString = username,
                SubName      = subName,
                ThingID      = thingID,
                Type         = Models.BannedEntity.EntityType.User
            };
            var conn = await GetSettings(subName);

            DAL.DirtbagDAL dirtbag = new DAL.DirtbagDAL();
            await dirtbag.AddToBanList(conn, new List <Models.BannedEntity>() { toBan });
        }
Exemple #7
0
        public async Task <bool> BanChannel(Models.BannedEntity entity, string channelID, string mediaAuthor, Models.VideoProvider vidProvider)
        {
            string query = @"
insert into public.sentinel_blacklist(subreddit_id, media_channel_id, media_author, media_platform_id, blacklist_utc, blacklist_by, media_channel_url)
SELECT id, @channelID, @mediaAuthor, @platformID, @BanDate, @BannedBy, @ChannelURL
from public.subreddit where subreddit_name like @SubName 
";

            try
            {
                await sentinelConn.ExecuteAsync(query, new { channelID, mediaAuthor, platformID = (int)vidProvider, entity.BanDate, entity.BannedBy, entity.ChannelURL, entity.SubName });
            }
            catch (Npgsql.PostgresException ex)
            {
                if (ex.SqlState == "23505")
                {
                    return(false);
                }

                throw;
            }
            return(true);
        }
Exemple #8
0
 public async Task BanUser( string subName, string username, string reason, string thingID, string bannedBy ) {
     Models.BannedEntity toBan = new Models.BannedEntity() {
         BanDate = DateTime.UtcNow,
         BannedBy = bannedBy,
         BanReason = reason,
         EntityString = username,
         SubName = subName,
         ThingID = thingID,
         Type = Models.BannedEntity.EntityType.User
     };
     var conn = await GetSettings( subName );
     DAL.DirtbagDAL dirtbag = new DAL.DirtbagDAL();
     await dirtbag.AddToBanList( conn, new List<Models.BannedEntity>() { toBan } );
 }
Exemple #9
0
 public async Task BanChannel( string subName, string url, string reason, string thingID, string bannedBy ) {
     DAL.YouTubeDAL ytDAL = new DAL.YouTubeDAL();
     string ytVidID = Helpers.YouTubeHelpers.ExtractVideoId( url );
     if ( string.IsNullOrWhiteSpace( ytVidID ) )
         throw new ArgumentException( $"Couldn't extract YouTube video ID from url: {url}" );
     string channelID = await ytDAL.GetChannelID( ytVidID );
     Models.BannedEntity toBan = new Models.BannedEntity() {
         BanDate = DateTime.UtcNow,
         BannedBy = bannedBy,
         BanReason = reason,
         EntityString = channelID,
         SubName = subName,
         ThingID = thingID,
         Type = Models.BannedEntity.EntityType.Channel
     };
     var conn = await GetSettings( subName );
     DAL.DirtbagDAL dirtbag = new DAL.DirtbagDAL();
     await dirtbag.AddToBanList(conn, new List<Models.BannedEntity>() { toBan } );
 }