예제 #1
0
        public static string RemoveBadWords(string input)
        {
            int bwLength = BadWords.Count;

            for (int i = 0; i < bwLength; i++)
            {
                try
                {
                    string bw = BadWords[i];
                    if (bw.StartsWith("regex::", StringComparison.OrdinalIgnoreCase))
                    {
                        bw = bw.Substring(7);
                        Regex regx = new Regex(bw, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        input = regx.Replace(input, "***");
                    }
                    else
                    {
                        input = input.Replace(bw, "***", StringComparison.OrdinalIgnoreCase);
                    }
                }
                catch (Exception ex)
                {
                    NLogManager.PublishException(ex);
                }
            }

            return(input);
        }
예제 #2
0
        public static string ReplaceVN(string input)
        {
            if (ReplaceVNs == null || ReplaceVNs.Count < 1)
            {
                if (Monitor.TryEnter(ReplaceVNs, 60000))
                {
                    try
                    {
                        ReplaceVNs.TryAdd("[@ÅÄäẢÃÁÀẠảãáàạÂĂẨẪẤẦẬẩẫấầậẲẴẮẰẶẳẵắằặ]+", "a");
                        ReplaceVNs.TryAdd("[ß]+", "b");
                        ReplaceVNs.TryAdd("[Ç€]+", "c");
                        ReplaceVNs.TryAdd("[ËẺẼÉÈẸẻẽéèẹÊỂỄẾỀỆêểễếềệ]+", "e");
                        ReplaceVNs.TryAdd("[ÏιỈĨÍÌỊỉĩíìị]+", "i");
                        ReplaceVNs.TryAdd("[ØÖöΘ☻❂ỎÕÓÒỌỏõóòọÔỔỖỐỒỘôổỗốồộƠỞỠỚỜỢơởỡớờợ0]+", "o");
                        ReplaceVNs.TryAdd("[Šš]+", "s");
                        ReplaceVNs.TryAdd("[τ]+", "t");
                        ReplaceVNs.TryAdd("[ÜỦŨÙỤÚủũúùụỬỮỨỪỰửữứừự]+", "u");
                        ReplaceVNs.TryAdd("[•,;:]+", ".");
                    }
                    finally
                    {
                        Monitor.Exit(ReplaceVNs);
                    }
                }
            }

            foreach (string key in ReplaceVNs.Keys)
            {
                try
                {
                    Regex regx = new Regex(key, RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    input = regx.Replace(input, ReplaceVNs[key]);

                    //NLogManager.LogMessage(key + " : " + input);
                }
                catch (Exception ex)
                {
                    NLogManager.PublishException(ex);
                }
            }

            return(input);
        }
예제 #3
0
        public static string RemoveBadLinks(string input, out bool Flag)
        {
            input = CutOff(input, " '`~");
            input = ReplaceVN(input);

            Flag = false;
            int bwLength = BadLinks.Count;

            for (int i = 0; i < bwLength; i++)
            {
                try
                {
                    string bl = BadLinks[i];
                    if (bl.StartsWith("regex::", StringComparison.OrdinalIgnoreCase))
                    {
                        bl = bl.Substring(7);
                        Regex regx = new Regex(bl, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        if (regx.IsMatch(input))
                        {
                            Flag = true;
                        }
                        input = regx.Replace(input, "*");
                    }
                    else
                    {
                        int countLength = input.Length;
                        input = input.Replace(bl, "*", StringComparison.OrdinalIgnoreCase);
                        if (input.Length != countLength)
                        {
                            Flag = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    NLogManager.PublishException(ex);
                }
            }

            return(input);
        }
예제 #4
0
 private static void LoadKeywordReplace()
 {
     try
     {
         string key = "KEYWORDREPLACE_FILE";
         if (BicCache.ReadCache(key) == null)
         {
             XDocument xmldoc         = XDocument.Load(KEYWORDREPLACE_FILE);
             IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe;
             var dt = new DataTable();
             dt.Columns.Add("text");
             dt.Columns.Add("replace");
             foreach (XElement xe in q)
             {
                 DataRow row = dt.NewRow();
                 row[0] = xe.Attribute("text").Value;
                 row[1] = xe.Attribute("replace").Value;
                 dt.Rows.Add(row); // Thêm dòng mới vào dtb
             }
             List <ObjKeywordReplace> Data = dt.AsEnumerable().Select(m => new ObjKeywordReplace()
             {
                 text    = m.Field <string>("text"),
                 replace = m.Field <string>("replace"),
             }).ToList();
             KeywordReplace = Data;
             BicCache.CacheData(key, KeywordReplace);
         }
         else
         {
             KeywordReplace = (List <ObjKeywordReplace>)BicCache.ReadCache(key);
         }
     }
     catch (Exception ex)
     {
         NLogManager.PublishException(ex);
     }
 }
예제 #5
0
        static ChatFilter()
        {
            if (KeywordReplace == null || KeywordReplace.Count < 1)
            {
                try
                {
                    NLogManager.LogMessage(string.Format("Load file keyword replace: {0}", KEYWORDREPLACE_FILE));
                    if (File.Exists(KEYWORDREPLACE_FILE))
                    {
                        LoadKeywordReplace();
                    }
                }
                catch (Exception e)
                {
                    NLogManager.PublishException(e);
                }
            }

            if (BadWords == null || BadWords.Count < 1)
            {
                if (Monitor.TryEnter(lockLoadBadWords, 60000))
                {
                    try
                    {
                        NLogManager.LogMessage(string.Format("Load file bad word: {0}", BLACKLIST_FILE));
                        if (File.Exists(BLACKLIST_FILE))
                        {
                            //string[] allText = File.ReadAllLines(BADWORDS_FILE);
                            //BadWords = new List<string>(allText);
                            LoadBlackList();
                        }
                    }
                    catch (Exception e)
                    {
                        NLogManager.PublishException(e);
                    }
                    finally
                    {
                        Monitor.Exit(lockLoadBadWords);
                    }
                }
            }

            if (BadLinks == null || BadLinks.Count < 1)
            {
                if (Monitor.TryEnter(lockLoadBadLinks, 60000))
                {
                    try
                    {
                        NLogManager.LogMessage(string.Format("Load file bad links: {0}", BADLINKS_FILE));
                        if (File.Exists(BADLINKS_FILE))
                        {
                            string[] allText = File.ReadAllLines(BADLINKS_FILE);

                            BadLinks = new List <string>(allText);
                        }
                    }
                    catch (Exception e)
                    {
                        NLogManager.PublishException(e);
                    }
                    finally
                    {
                        Monitor.Exit(lockLoadBadLinks);
                    }
                }
            }

            if (ListAccountBlock == null || ListAccountBlock.Count < 1)
            {
                try
                {
                    NLogManager.LogMessage(string.Format("Load file Account Block: {0}", ACCOUNTBLOCK_FILE));
                    if (File.Exists(ACCOUNTBLOCK_FILE))
                    {
                        LoadAccountBlock();
                    }
                }
                catch (Exception e)
                {
                    NLogManager.PublishException(e);
                }
            }
            //if (BanUsers == null || BanUsers.Count < 1)
            //{
            //    if (Monitor.TryEnter(lockLoadBanUsers, 60000))
            //    {
            //        try
            //        {
            //            NLogManager.LogMessage(string.Format("Load file banned user: {0}", BANUSERS_FILE));
            //            if (File.Exists(BANUSERS_FILE))
            //            {
            //                string[] allText = File.ReadAllLines(BANUSERS_FILE);

            //                BanUsers.AddRange(allText);
            //            }
            //        }
            //        catch (Exception e)
            //        {
            //            NLogManager.PublishException(e);
            //        }
            //        finally
            //        {
            //            Monitor.Exit(lockLoadBanUsers);
            //        }
            //    }
            //}
        }