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

            Assert.That(result, Is.EqualTo("0 ***** given"));
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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 ChatOnOnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message,
                                  ref bool isHandled)
 {
     if (!_configuration.Enabled)
     {
         return;
     }
     foreach (var payload in message.Payloads)
     {
         if (payload is TextPayload textPayload)
         {
             textPayload.Text = _profanityFilter.CensorString(textPayload.Text);
         }
     }
 }
Exemplo n.º 5
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);
        }