public void GivenSentenceWithProfanity_DetectAllProfanities_FlagsProfanities()
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.CensorString("0 shits given");

            Assert.That(result, Is.EqualTo("0 ***** given"));
        }
        public void GivenSentenceWithProfanity_DetectAllProfanities_FlagsProfanities()
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.DetectAllProfanities("0 shits given");

            Assert.That(result, Contains.Item("shits"));
        }
        public void GivenProfanityThatLibraryDoesNotRecognise_IsProfanity_IsFalse()
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.IsProfanity("sh1tface");

            Assert.That(result, Is.False);
        }
        public void GivenPluralProfanity_IsProfanity_IsFalse()
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.IsProfanity("shits");

            Assert.That(result, Is.True);
        }
        public void GivenWordsWhichAreNotProfane_IsProfanity_IsFalse(string wordWhichIsNotProfane)
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.IsProfanity(wordWhichIsNotProfane);

            Assert.That(result, Is.False);
        }
        public void GivenProfanities_IsProfanity_IsTrue(string profanity)
        {
            var sut    = new ProfanityFilter.ProfanityFilter();
            var result = sut.IsProfanity(profanity);

            Assert.That(result, Is.True);
        }
Ejemplo n.º 7
0
        public static async Task <ProfanityFilter.ProfanityFilter> GetProfanityFilterForServer(Server server)
        {
            // TODO Look into caching this some how...
            // TODO Look into caching in general (Cache servers/guilds also for example)
            // Looks like MonkeyCache just uses a SQLite db to caches and that is what we are doing anyway
            // Maybe do some kind of in memeory caching?
            if (ProfanityRepository == null)
            {
                Log.Warning("ProfanityRepository is null!");
                throw new InvalidOperationException("ProfanityRepostiry cannot be null, please set it before using the ProfanityHelper!");
            }

            ProfanityFilter.ProfanityFilter filter = new ProfanityFilter.ProfanityFilter();
            filter.RemoveProfanity(_globalAllowedWords);
            filter.AddProfanity(_globalBannedWords);

            var allowedWords = await ProfanityRepository.GetAllowedProfanity(server.GuildId);

            var blockedWord = await ProfanityRepository.GetBlockedProfanity(server.GuildId);

            foreach (var word in allowedWords)
            {
                filter.RemoveProfanity(word.Word);
            }

            foreach (var word in blockedWord)
            {
                filter.AddProfanity(word.Word);
            }

            return(filter);
        }
Ejemplo n.º 8
0
        public async Task SendMessage(string user, string message)
        {
            string accessToken = await Context.GetHttpContext().GetTokenAsync("access_token");

            // Préparation de l'appel à l'API
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            // Récurération des données et convertion des données dans le bon type
            string content = await client.GetStringAsync(_configuration["URLAPI"] + "api/Insults");

            string content1 = await client.GetStringAsync(_configuration["URLAPI"] + "api/account/getUserInfo");

            string content2 = await client.GetStringAsync(_configuration["URLAPI"] + "api/Data/BotCommands");

            List <BotCommand> botCommands = JsonConvert.DeserializeObject <List <BotCommand> >(content2);

            AspNetUser user1       = JsonConvert.DeserializeObject <AspNetUser>(content1);
            var        httpContent = new StringContent("test", Encoding.UTF8, "application/json");

            var response = await UserHandler.tokenClient.Conversations.PostActivityAsync(UserHandler.ConversationId,
                                                                                         new Activity()
            {
                Type = "message",
                Text = message,
                From = UserHandler.channelAccount.Where(x => x.Name.Equals(user1.UserName)).FirstOrDefault(),
            }).ConfigureAwait(false);


            ActivitySet activites = await UserHandler.tokenClient.Conversations.GetActivitiesAsync(UserHandler.ConversationId);

            List <Insult> insults = JsonConvert.DeserializeObject <List <Insult> >(content);
            List <string> words   = insults.Select(i => i.InsultName).ToList();


            ProfanityFilter.ProfanityFilter filter = new ProfanityFilter.ProfanityFilter();
            filter.AddProfanity(words);
            //string censored =
            string censored = filter.CensorString(ReceiveActivities(activites, user1.UserName));

            await Clients.All.SendAsync("ReceiveMessage", user, censored);

            ActivitySet botActivites = await UserHandler.tokenClient.Conversations.GetActivitiesAsync(UserHandler.ConversationId);

            string bot = null;

            if (message.Contains("/giphy"))
            {
                bot = ReceiveBotActivities(botActivites, "lovemirroring-bot");
                await Clients.All.SendAsync("ImageReceive", "bot", bot);
            }
            else
            {
                bot = ReceiveBotActivities(botActivites, "lovemirroring-bot");
                await Clients.All.SendAsync("ReceiveMessage", "bot", bot);
            }
        }
Ejemplo n.º 9
0
        private static string Censor(string value)
        {
            var    filter   = new ProfanityFilter.ProfanityFilter();
            string censored = filter.CensorString(value).Replace('*', '_');

            if (filter.ContainsProfanity(string.Concat(censored.Where(c => c != '_'))))
            {
                return(new string('_', value.Length));
            }
            return(censored);
        }
 private void InitProfanityFilter()
 {
     if (!_configuration.UseDefaults)
     {
         _profanityFilter = new ProfanityFilter.ProfanityFilter(_configuration.BlockedWords);
     }
     else
     {
         _profanityFilter = new ProfanityFilter.ProfanityFilter();
         foreach (var word in _configuration.AllowedWords)
         {
             _profanityFilter.RemoveProfanity(word);
         }
         foreach (var word in _configuration.BlockedWords)
         {
             _profanityFilter.AddProfanity(word);
         }
     }
 }
Ejemplo n.º 11
0
        public async Task SendMessage(string username, string userId, string friendname, string message, string connId, string talkId)
        {
            // Ajouter la connexion au singleton
            AddConnection(username, friendname, connId);

            string accessToken = await Context.GetHttpContext().GetTokenAsync("access_token");

            // Préparation de l'appel à l'API
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            // Récupérer la liste des insultes
            string insultsRequest = await client.GetStringAsync(_configuration["URLAPI"] + "api/Insults");

            List <Insult> insults = JsonConvert.DeserializeObject <List <Insult> >(insultsRequest);
            // Filtrer les insultes
            List <string> words = insults.Select(i => i.InsultName).ToList();

            ProfanityFilter.ProfanityFilter filter = new ProfanityFilter.ProfanityFilter();
            filter.AddProfanity(words);
            string censored = filter.CensorString(message);

            Message messageDB = new Message
            {
                MessageDate = DateTime.Now,
                MessageText = censored,
                Id          = userId,
                TalkId      = short.Parse(talkId)
            };

            // Récupérer la connexion du récepteur
            string connectionFriendId = _connectionPCs
                                        .Where(c => c.username == friendname && c.friendname == username)
                                        .OrderByDescending(c => c.dateConnection)
                                        .Select(c => c.connectionId)
                                        .FirstOrDefault();

            // Si existant envoyer au récepteur
            if (connectionFriendId != null && connectionFriendId != "")
            {
                await Clients.Client(connectionFriendId).SendAsync("ReceiveMessage", username, censored);
            }

            // Récupérer la connexion de l'expéditeur
            string connectionUserId = _connectionPCs
                                      .Where(c => c.username == username)
                                      .OrderByDescending(c => c.dateConnection)
                                      .Select(c => c.connectionId)
                                      .FirstOrDefault();

            // Si existant envoyer à l'expéditeur
            if (connectionUserId != null && connectionUserId != "")
            {
                await Clients.Client(connectionUserId).SendAsync("ReceiveMessage", username, censored);
            }

            // Enregistrer le message dans la base de données
            StringContent       httpContent = new StringContent(messageDB.ToJson(), Encoding.UTF8, "application/json");
            HttpResponseMessage response    = await client.PostAsync(_configuration["URLAPI"] + "api/PrivateChat/CreateMessage", httpContent);
        }
 public ProfanityController(IConfiguration config)
 {
     _profanityFilter = new ProfanityFilter.ProfanityFilter();
     _profanityFilter.AddProfanity(WordList());
     _config = config;
 }
Ejemplo n.º 13
0
 public CommentflixController(DBConnection context)
 {
     _profanityFilter = new ProfanityFilter.ProfanityFilter();
     _context         = context;
 }
Ejemplo n.º 14
0
 public static void Initialise()
 {
     filter = new ProfanityFilter.ProfanityFilter();
 }
Ejemplo n.º 15
0
        public ValidationProvider()
        {
            var bannedWords = Constants.BANNEDWORDSVALIDATOR.Split(',').ToList();

            _censor = new ProfanityFilter.ProfanityFilter(bannedWords);
        }