Exemple #1
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);
        }
Exemple #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);
            }
        }
 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);
         }
     }
 }
Exemple #4
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;
 }