private static void LoadAccountBlock() { try { string key = "ACCOUNTBLOCK_FILE"; if (BicCache.ReadCache(key) == null) { XDocument xmldoc = XDocument.Load(ACCOUNTBLOCK_FILE); IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe; var dt = new DataTable(); dt.Columns.Add("key"); dt.Columns.Add("name"); dt.Columns.Add("accountid"); dt.Columns.Add("reasonblock"); dt.Columns.Add("namereasonblock"); dt.Columns.Add("typeblock"); dt.Columns.Add("endtimeblock"); dt.Columns.Add("createDate"); foreach (XElement xe in q) { DataRow row = dt.NewRow(); row[0] = xe.Attribute("key").Value; row[1] = xe.Attribute("name").Value; row[2] = xe.Attribute("accountid").Value; row[3] = xe.Attribute("reasonblock").Value; row[4] = xe.Attribute("namereasonblock").Value; row[5] = xe.Attribute("typeblock").Value; row[6] = xe.Attribute("endtimeblock").Value; row[7] = xe.Attribute("createDate").Value; dt.Rows.Add(row); // Thêm dòng mới vào dtb } List <ListAccountBlock> Data = ListAccountBlock = dt.AsEnumerable().Select(m => new ListAccountBlock() { key = m.Field <string>("key"), name = m.Field <string>("name"), accountid = m.Field <string>("accountid"), reasonblock = m.Field <string>("reasonblock"), namereasonblock = m.Field <string>("namereasonblock"), typeblock = m.Field <string>("typeblock"), endtimeblock = m.Field <string>("endtimeblock"), createDate = m.Field <string>("createDate") }).ToList(); BicCache.CacheData(key, Data); } else { ListAccountBlock = (List <ListAccountBlock>)BicCache.ReadCache(key); } } catch (Exception ex) { NLogManager.LogMessage(">> Ex LoadAccountBlock:" + ex.Message); } }
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); }
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); }
public static bool AddBadWord(string word) { if (Monitor.TryEnter(lockLoadBadWords, 60000)) { try { File.AppendAllText(BADWORDS_FILE, Environment.NewLine + word); BadWords.Add(word); NLogManager.LogMessage(string.Format("Admins has been added bad word: word={0}", word)); return(true); } finally { Monitor.Exit(lockLoadBadWords); } } return(false); }
public static bool AddBadLink(string link) { if (Monitor.TryEnter(lockLoadBadLinks, 60000)) { try { File.AppendAllText(BADLINKS_FILE, Environment.NewLine + link); BadLinks.Add(link); NLogManager.LogMessage(string.Format("Admins has been added bad link: link={0}", link)); return(true); } finally { Monitor.Exit(lockLoadBadLinks); } } return(false); }
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); } }
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); // } // } //} }