Esempio n. 1
0
        public string ExecuteIfMatches(IrcMessage msg, IrcClient client)
        {
            try
            {
                string haystack = "";

                if (TriggerType == TriggerType.Raw)
                {
                    haystack = msg.RawMessage;
                }
                else
                {
                    haystack = new PrivateMessage(msg).Message;
                }

                if (Matches(haystack))
                {
                    if (TriggerResult == TriggerResult.Raw)
                    {
                        client.SendRawMessage(ResultString);
                    }
                    else if (TriggerResult == TriggerResult.Irc)
                    {
                        client.SendMessage(ResultString, new PrivateMessage(msg).Source);
                    }
                    else if (TriggerResult == TriggerResult.Modify)
                    {
                        string temp = haystack;

                        if (FixHomoglyphs)
                        {
                            temp = Table.Purify(temp);
                        }
                        if (Strip)
                        {
                            temp = Utilities.Sanitize(temp);
                        }
                        if (AsciiOnly)
                        {
                            temp = new string(temp.Where(c => (char.IsLetterOrDigit(c) || char.IsSymbol(c) || MatchString.Contains(c))).ToArray());
                        }

                        switch (TriggerMatchType)
                        {
                        case TriggerMatchType.Contains:
                            return(temp.Replace(MatchString, ResultString));

                        case TriggerMatchType.EndsWith:
                            return(temp.Substring(0, temp.Length - MatchString.Length) + ResultString);

                        case TriggerMatchType.StartsWith:
                            return(ResultString + temp.Substring(MatchString.Length));

                        case TriggerMatchType.Regex:
                            return(Regex.Replace(temp, MatchString, m => { return ResultString; }, Insensitive ? RegexOptions.IgnoreCase : RegexOptions.None));
                        }
                    }
                    else if (TriggerResult == TriggerResult.Rewrite)
                    {
                        return(ResultString);
                    }
                }
            }
            catch
            {
            }

            return("");
        }
Esempio n. 2
0
        public bool Matches(string msg)
        {
            if (FixHomoglyphs)
            {
                msg = Table.Purify(msg);
            }

            if (Insensitive)
            {
                msg = msg.ToLower();
            }

            if (Strip)
            {
                msg = Utilities.Sanitize(msg);
            }

            if (AsciiOnly)
            {
                msg = new string(msg.Where(c => (char.IsLetterOrDigit(c) || char.IsSymbol(c) || MatchString.Contains(c))).ToArray());
            }

            bool matches = false;

            switch (TriggerMatchType)
            {
            case TriggerMatchType.Contains:
                matches = msg.Contains(MatchString);
                break;

            case TriggerMatchType.EndsWith:
                matches = msg.EndsWith(MatchString);
                break;

            case TriggerMatchType.StartsWith:
                matches = msg.StartsWith(MatchString);
                break;

            case TriggerMatchType.Regex:
                matches = Regex.IsMatch(msg, MatchString);
                break;
            }

            return(matches);
        }