private bool msgMatchesCrit(Settings.ChatChannel cc, string msg) { if (!cc.UseKeywords && !cc.UseRegex) { return(true); } if (cc.UseKeywords) { if (stringContainsKeywords(msg, cc.keywords)) { return(true); } } if (cc.UseRegex) { Regex r = new Regex(cc.Regex, RegexOptions.IgnoreCase); if (r.Match(msg).Success) { return(true); } } return(false); }
private Settings.ChatChannel buildChatChannel(bool enabled, bool useKeywords, bool useRegex, string keywords, string regex, bool Reply, string ReplyTxt) { var cc = new Settings.ChatChannel(); cc.Enabled = enabled; if (!string.IsNullOrEmpty(keywords)) { cc.keywords = keywords.Split(','); } if (useKeywords) { cc.UseKeywords = true; } else { cc.UseKeywords = false; } if (useRegex) { var pattern = regex; if (isValidRegex(pattern)) { cc.UseRegex = true; cc.Regex = pattern; } else { MessageBox.Show("Regex is invalid: \r\n" + pattern); cc.Regex = pattern; //Save pattern anyway. cc.UseRegex = false; } } else { cc.Regex = regex; cc.UseRegex = false; } if (!string.IsNullOrEmpty(ReplyTxt)) { cc.ReplyText = ReplyTxt; } cc.Reply = Reply; return(cc); }