Exemple #1
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string result = target;//MakeCaseInsensitive.TransformInput(target);

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b" + @p2.Trim() + "\\b";
                string match       = @p2;
                string replacement = dictionary.grabSetting(pattern);
                if (replacement.StartsWith(" "))
                {
                    replacement = " ||" + replacement.TrimStart();
                }
                else
                {
                    replacement = "||" + replacement;
                }
                if (replacement.EndsWith(" "))
                {
                    replacement = replacement.TrimEnd() + "|| ";
                }
                else
                {
                    replacement = replacement + "||";
                }
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace("||", ""));
        }
Exemple #2
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2      = ApplySubstitutions.makeRegexSafe(pattern);
                string valueP2 = dictionary.grabSetting(pattern).Trim();

                Regex regPattern = new Regex(p2, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                Match match      = regPattern.Match(result);
                if (match.Success)
                {
                    string match1 = p2.TrimEnd().TrimStart();
                    if (!String.IsNullOrEmpty(match1))
                    {
                        string replacement = marker + dictionary.grabSetting(pattern) + marker;
                        result = Regex.Replace(result, match1, replacement, RegexOptions.IgnoreCase);
                    }
                }
                //result = Regex.Replace(result, p2, valueP2, RegexOptions.IgnoreCase);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                //string match = p2.TrimEnd().TrimStart();
                //string replacement = marker+dictionary.grabSetting(pattern).Trim()+marker;
                //result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
            //return result;
        }
Exemple #3
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="UserID">The GUID of the user</param>
        /// <param name="bot">the bot the user is connected to</param>
		public User(string UserID, AIMLbot.Bot bot)
		{
            if (UserID.Length > 0)
            {
                this.id = UserID;
                this.bot = bot;
                this.Predicates = new AIMLbot.Utils.SettingsDictionary(this.bot);
                this.bot.DefaultPredicates.Clone(this.Predicates);
                this.Predicates.addSetting("topic", "*");
            }
            else
            {
                throw new Exception("The UserID cannot be empty");
            }
		}
Exemple #4
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="UserID">The GUID of the user</param>
 /// <param name="bot">the bot the user is connected to</param>
 public User(string UserID, AIMLbot.Bot bot)
 {
     if (UserID.Length > 0)
     {
         this.id         = UserID;
         this.bot        = bot;
         this.Predicates = new AIMLbot.Utils.SettingsDictionary(this.bot);
         this.bot.DefaultPredicates.Clone(this.Predicates);
         this.Predicates.addSetting("topic", "*");
     }
     else
     {
         throw new Exception("The UserID cannot be empty");
     }
 }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="UserID">The GUID of the user</param>
 /// <param name="bot">the bot the user is connected to</param>
 public User(string UserID, AIMLbot.Bot bot)
 {
     if (UserID.Length > 0 && bot != null)
     {
         this.id         = UserID;
         this.bot        = bot;
         this.Predicates = new AIMLbot.Utils.SettingsDictionary(this.bot);
         this.bot.DefaultPredicates.Clone(this.Predicates);
         this.Predicates.addSetting("topic", "*");
     }
     else
     {
         Debug.LogWarning("The UserID is empty or no bot was passed.");
     }
 }
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                string match       = "\\b" + p2.TrimEnd().TrimStart() + "\\b";
                string replacement = marker + dictionary.grabSetting(pattern).Trim() + marker;
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
        }