Ejemplo n.º 1
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.Core.Bot bot)
 {
     if (UserID.Length > 0)
     {
         this.id         = UserID;
         this.bot        = bot;
         this.Predicates = new AIMLBot.Core.Utils.SettingsDictionary(this.bot);
         this.bot.DefaultPredicates.Clone(this.Predicates);
         this.Predicates.addSetting("topic", "*");
     }
     else
     {
         throw new Exception("The UserID cannot be empty");
     }
 }
Ejemplo n.º 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.Core.Bot bot, AIMLBot.Core.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, ""));
        }