Beispiel #1
0
        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);
        }
Beispiel #2
0
        private Settings.ChatChannel buildChatChannel(bool enabled, bool useKeywords, bool useRegex, bool pushbullet, string keywords, string regex)
        {
            var cc = new Settings.ChatChannel();

            cc.Enabled           = enabled;
            cc.PushBulletEnabled = pushbullet;

            if (!String.IsNullOrEmpty(keywords))
            {
                cc.Keywords = keywords.Split(',');
            }

            if (useKeywords)
            {
                cc.UseKeywords = true;
            }
            else
            {
                cc.UseKeywords = false;
            }

            if (useRegex)
            {
                var pattern = regex;
                if (Utils.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;
            }
            return(cc);
        }