/*
     * void OnGUI () {
     *      // Enable Word warp
     *      GUI.skin.label.wordWrap = true;
     *      // Make a background box
     *      GUI.Box(new Rect(10,10,300,150), "Chat with a Chatbot");
     *      // Make output label
     *      GUI.Label (new Rect (20, 30, 280, 40), Output_Text);
     *      // Make a text field that modifies Input_Text.
     *      Input_Text = GUI.TextField (new Rect (20, 100, 280, 20), Input_Text, 100);
     *      // If send button or enter pressed
     *      if(((Event.current.keyCode == KeyCode.Return)||GUI.Button(new Rect(250,130,50,20),"Send")) && (Input_Text != "")) {
     *              // Prepare Variables
     *              // You don't need to care, wether Only Jurassics or only Program #'s Variables
     *              // are changed. This is managed immediate intern every time you change a global
     *              // variable in Program # or Jurassic.
     *              // bot.jscript_engine.SetGlobalValue("abc",15);
     *
     *              request.rawInput = Input_Text;
     *              request.StartedOn = DateTime.Now;
     *              result = bot.Chat(request);
     *              Output_Text = result.Output;
     *              Input_Text = "";
     *
     *              // Gather Variables
     *              // bot.jscript_engine.GetGlobalValue<string>("abc");
     *      }
     * }*/

    public string GetAnswer(string input)
    {
        request.rawInput  = input;
        request.StartedOn = DateTime.Now;
        result            = bot.Chat(request);
        return(result.Output);
    }
Beispiel #2
0
    // Start is called before the first frame update
    // Update is called once per frame
    void OnGUI()
    {
        //Input_Text = CommText.text.ToString();
        // Enable Word warp
        //GUI.skin.label.wordWrap = true;
        // Make a background box
        //GUI.Box(new Rect(10, 10, 300, 500), "Chat with a Chatbot");
        // Make output label
        //GUI.Label(new Rect(20, 30, 280, 40), Output_Text);
        // Make a text field that modifies Input_Text.
        if (Event.current.keyCode == KeyCode.Return)
        {
            // Prepare Variables
            // You don't need to care, wether Only Jurassics or only Program #'s Variables
            // are changed. This is managed immediate intern every time you change a global
            // variable in Program # or Jurassic.
            // bot.jscript_engine.SetGlobalValue("abc",15);

            request.rawInput  = CommText.text.ToString();
            request.StartedOn = DateTime.Now;
            result            = bot.Chat(request);
            ResponseText.text = result.Output;
            Input_Text        = "";
            CommText.text     = "";

            // Gather Variables
            // bot.jscript_engine.GetGlobalValue<string>("abc");
        }
    }
Beispiel #3
0
    void Start()

    {
        //  Debug.Log("aaaaa");
        LogSystem.InstallDefaultReactors();

        //  Create credential and instantiate service
        Credentials credentials = new Credentials("c20a3f60-9df3-4d5b-86e5-027ccde5c42c", "mnCUwtXFpNSl", "https://gateway.watsonplatform.net/conversation/api");

        _conversation             = new Conversation(credentials);
        _conversation.VersionDate = _conversationVersionDate;

        bot     = new AIMLbot.Bot();
        user    = new AIMLbot.User("User", bot);
        request = new AIMLbot.Request("", user, bot);
        result  = new AIMLbot.Result(user, bot, request);
        bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
        // Load AIML files from AIML path defined in Settings.xml
        bot.loadAIMLFromFiles();
        if (bot != null)
        {
            bot.UseJavaScript = true;
        }


        //   TextToSpeechMark ttsm = gameObject.GetComponent<TextToSpeechMark>();
        //  AskQuestion();
    }
Beispiel #4
0
    void OnGUI()
    {
        // Enable Word warp
        GUI.skin.label.wordWrap = true;
        // Make a background box
        GUI.Box(new Rect(10, 10, 300, 500), "Chat with a Chatbot");
        // Make output label
        GUI.Label(new Rect(20, 30, 280, 40), Output_Text);
        // Make a text field that modifies Input_Text.
        Input_Text = GUI.TextField(new Rect(20, 100, 280, 20), Input_Text, 100);
        // If send button or enter pressed
        if (((Event.current.keyCode == KeyCode.Return) || GUI.Button(new Rect(250, 130, 50, 20), "Send")) && (Input_Text != ""))
        {
            // Prepare Variables
            // You don't need to care, wether Only Jurassics or only Program #'s Variables
            // are changed. This is managed immediate intern every time you change a global
            // variable in Program # or Jurassic.
            // bot.jscript_engine.SetGlobalValue("abc",15);

            request.rawInput  = Input_Text;
            request.StartedOn = DateTime.Now;
            result            = bot.Chat(request);
            Output_Text       = result.Output;
            Input_Text        = "";

            // Gather Variables
            // bot.jscript_engine.GetGlobalValue<string>("abc");
        }
    }
Beispiel #5
0
 public void setupMockObjects()
 {
     this.mockBot = new Bot();
     this.mockUser = new User("1", this.mockBot);
     this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot);
     this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *");
     this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest);
 }
Beispiel #6
0
 public void chatbotanswer()
 {
     request.rawInput  = _questiontext.text;
     request.StartedOn = DateTime.Now;
     result            = bot.Chat(request);
     _answer.text      = result.Output;
     //  TextToSpeechMark ttsm = gameObject.GetComponent<TextToSpeechMark>();
     // ttsm.Synthesize(_answer.text);
 }
Beispiel #7
0
 public void setupMockObjects()
 {
     this.mockBot = new Bot();
     this.mockBot.loadSettings();
     this.mockBot.loadAIMLFromFiles();
     this.mockUser = new User("1", this.mockBot);
     this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot);
     this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *");
     this.mockQuery.InputStar.Insert(0, "first star");
     this.mockQuery.InputStar.Insert(0, "second star");
     this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest);
 }
Beispiel #8
0
 public void setupMockObjects()
 {
     this.mockBot = new Bot();
     this.mockBot.loadSettings();
     this.mockBot.loadAIMLFromFiles();
     this.mockUser    = new User("1", this.mockBot);
     this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot);
     this.mockQuery   = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *");
     this.mockQuery.InputStar.Insert(0, "first star");
     this.mockQuery.InputStar.Insert(0, "second star");
     this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest);
 }
Beispiel #9
0
 public void setupMockObjects()
 {
     this.mockBot         = new Bot();
     this.mockUser        = new User("1", this.mockBot);
     this.mockRequest     = new Request("This is a test", this.mockUser, this.mockBot);
     this.mockQuery       = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *");
     this.mockResult      = new Result(this.mockUser, this.mockBot, this.mockRequest);
     this.possibleResults = new ArrayList();
     this.possibleResults.Add("random 1");
     this.possibleResults.Add("random 2");
     this.possibleResults.Add("random 3");
     this.possibleResults.Add("random 4");
     this.possibleResults.Add("random 5");
 }
Beispiel #10
0
 public void setupMockObjects()
 {
     this.mockBot = new Bot();
     this.mockUser = new User("1", this.mockBot);
     this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot);
     this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *");
     this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest);
     this.possibleResults = new ArrayList();
     this.possibleResults.Add("random 1");
     this.possibleResults.Add("random 2");
     this.possibleResults.Add("random 3");
     this.possibleResults.Add("random 4");
     this.possibleResults.Add("random 5");
 }
Beispiel #11
0
 /// <summary>
 /// Initialize our derived MonoBehaviour
 /// </summary>
 void Start()
 {
     CommText     = GameObject.Find("CommText").GetComponent <Text>();
     ResponseText = GameObject.Find("ResponseText").GetComponent <Text>();
     bot          = new AIMLbot.Bot();
     user         = new AIMLbot.User("User", bot);
     request      = new AIMLbot.Request("", user, bot);
     result       = new AIMLbot.Result(user, bot, request);
     bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
     bot.loadAIMLFromFiles();
     if (bot != null)
     {
         bot.UseJavaScript = true;
     }
 }
Beispiel #12
0
    /// <summary>
    /// Initialize our derived MonoBehaviour
    /// </summary>
    void Start()
    {
        // Initialize Program # variables
// For Webplayer plattform and WebGl
#if (UNITY_WEBPLAYER || UNITY_WEBGL)
        ProgramSharpWebplayerCoroutine WebplayerCoroutine = this.gameObject.GetComponent <ProgramSharpWebplayerCoroutine>();
        if (WebplayerCoroutine != null)
        {
            bot = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
        }
        else
        {
            Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode.");
        }
// Other plattforms
#else
        // Only for Windows, Linux and Mac OSX
        bot = new AIMLbot.Bot();
#endif
        user    = new AIMLbot.User("User", bot);
        request = new AIMLbot.Request("", user, bot);
        result  = new AIMLbot.Result(user, bot, request);
// Only for Windows, Linux, Mac OSX Android and IOS
#if !(UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_ANDROID || UNITY_IOS)
        // Load Settings from Xml file in config directory. Plattform dependend Path issues may
        // occur.
        bot.loadSettings(Application.dataPath + "/Chatbot/Program #/config/Settings.xml");
        // Load AIML files from AIML path defined in Settings.xml
        bot.loadAIMLFromFiles();
#endif
// Android and IOS release
#if (UNITY_ANDROID || UNITY_IOS)
        // Load Settings from Xml file in config directory within resources folder.
        bot.loadSettings("Chatbot/Program #/config/Settings");
        // Load AIML files from AIML path defined in Settings.xml
        bot.loadAIMLFromFiles();
#endif
        // Define to or not to use JavaScript (Jurassic) in AIML
        if (bot != null)
        {
            bot.UseJavaScript = true;
        }
    }
Beispiel #13
0
        public void testMultiCondition()
        {
            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test1", "match1");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 1 match 1 found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test1", "match2");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 1 match 2 found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test1", "");

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test2", "match1");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 2 match 1 found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test2", "match2");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 2 match 2 found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test2", "");


            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test3", "match test the star works");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("match * found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test3", "");


            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test3", "match test the star won't match this");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("default match found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test", "match4");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("default match found.", this.mockResult.RawOutput);
        }
Beispiel #14
0
        public void testMultiCondition()
        {
            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test1", "match1");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 1 match 1 found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test1", "match2");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 1 match 2 found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test1", "");

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test2", "match1");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 2 match 1 found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test2", "match2");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("test 2 match 2 found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test2", "");


            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test3", "match test the star works");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("match * found.", this.mockResult.RawOutput);
            this.mockUser.Predicates.addSetting("test3", "");


            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test3", "match test the star won't match this");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("default match found.", this.mockResult.RawOutput);

            this.mockRequest = new Request("test multi condition", this.mockUser, this.mockBot);
            this.mockUser.Predicates.addSetting("test", "match4");
            this.mockResult = this.mockBot.Chat(this.mockRequest);
            Assert.AreEqual("default match found.", this.mockResult.RawOutput);
        }
Beispiel #15
0
        public JsonResult chatbot(string text, string group)
        {
            string result = "";

            AIMLbot.Result res = _bot.Chat(text);

            bool isMatch = true;

            //AIMLbot.Request r = new Request(text, user, bot);
            //AIMLbot.Result res = bot.Chat(r);

            result = res.OutputSentences[0].ToString();
            if (result.Contains("NOT_MATCH"))
            {
                isMatch = false;
                result  = CauHoiLienQuan(text, group);
                if (String.IsNullOrEmpty(result))
                {
                    //result = NOT_MATCH[res.OutputSentences[0]];
                    result = res.OutputSentences[0].ToString();
                }
            }
            return(Json(new { message = res.OutputHtmlMessage, postback = res.OutputHtmlPostback, messageai = result, isCheck = isMatch }, JsonRequestBehavior.AllowGet));
        }
Beispiel #16
0
 public AIMLbot.Result Chat(string text, User userBot)//, AIMLbot.Utils.SettingsDictionary Predicates
 {
     AIMLbot.Request r      = new Request(text, userBot, _bot);
     AIMLbot.Result  result = _bot.Chat(r);
     return(result);
 }
Beispiel #17
0
 public void testRecursiveBlockCondition()
 {
     this.mockRequest = new Request("test block recursive call", this.mockUser, this.mockBot);
     this.mockResult  = this.mockBot.Chat(this.mockRequest);
     Assert.AreEqual("Test passed.", this.mockResult.RawOutput);
 }
Beispiel #18
0
        async void do_work(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            var key    = e.Argument as String;

            try
            {
                var bot = new Telegram.Bot.TelegramBotClient(key);
                await bot.SetWebhookAsync("");

                AIMLbot.Bot lazy = new AIMLbot.Bot();


                lazy.loadSettings();
                lazy.loadAIMLFromFiles();
                lazy.isAcceptingUserInput = false;
                AIMLbot.User us = new AIMLbot.User("Username", lazy);
                lazy.isAcceptingUserInput = true;


                bot.OnCallbackQuery += async(object sc, Telegram.Bot.Args.CallbackQueryEventArgs ev) =>
                {
                    Telegram.Bot.Types.FileToSend s;
                    var message = ev.CallbackQuery.Message;
                    if (ev.CallbackQuery.Data == "callback1")
                    {
                        s = new Telegram.Bot.Types.FileToSend("https://i.pinimg.com/originals/f7/e9/80/f7e980c9700c8395535b835e66f02a59.jpg");
                    }
                    else if (ev.CallbackQuery.Data == "callback2")
                    {
                        s = new Telegram.Bot.Types.FileToSend("https://static.independent.co.uk/s3fs-public/thumbnails/image/2012/02/29/22/pg-28-sloth-cooke.jpg");
                    }
                    await bot.SendPhotoAsync(message.Chat.Id, s, "Sure! But... not today :)");

                    await bot.AnswerCallbackQueryAsync(ev.CallbackQuery.Id);
                };

                bot.OnUpdate += async(object su, Telegram.Bot.Args.UpdateEventArgs evu) =>
                {
                    if (evu.Update.CallbackQuery != null || evu.Update.InlineQuery != null)
                    {
                        return;
                    }
                    var update  = evu.Update;
                    var message = update.Message;
                    if (message == null)
                    {
                        return;
                    }
                    if (message.Type == Telegram.Bot.Types.Enums.MessageType.TextMessage)
                    {
                        if (message.Text[0] == '/')
                        {
                            if (message.Text == "/test")
                            {
                                await bot.SendTextMessageAsync(message.Chat.Id, "Yeah...",
                                                               replyToMessageId : message.MessageId);
                            }

                            if (message.Text == "/sleep")
                            {
                                var s = new Telegram.Bot.Types.FileToSend("https://beano-uploads-production.imgix.net/store/f4046f22dffe92e3f2167accb6942f788159d0f979f970dcda59f1d0e529?auto=compress&w=752&h=423&fit=min");
                                await bot.SendPhotoAsync(message.Chat.Id,
                                                         s, "Yeeeeeeeeeah, sleeeeeeeeep!");
                            }

                            if (message.Text == "/song")
                            {
                                var s = new Telegram.Bot.Types.FileToSend("http://store.naitimp3.ru/download/0/cGR1a0tRTWJwZW8wMlI2aitkT1UzVkxNdXE2dUNiRTAvcGRkeGphMTVFVTdQcGFURWlFOFQyUGZFTXJ6UVo4cWxVSUNza2NOQUpoZkJOU2ozYTJhWUpLSVdiUTRTanQrVmZnN1hQV1U5Tkk9/eels_i_need_some_sleep_(NaitiMP3.ru).mp3");
                                await bot.SendAudioAsync(message.Chat.Id, s, "", 4, "Eels", "I need some sleep...");
                            }

                            if (message.Text == "/work")
                            {
                                var keyboard = new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardMarkup(
                                    new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardButton[][]
                                {
                                    // First row
                                    new [] {
                                        // First column
                                        new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardCallbackButton("Work", "callback1"),

                                        // Second column
                                        new Telegram.Bot.Types.InlineKeyboardButtons.InlineKeyboardCallbackButton("Work harder", "callback2")
                                    },
                                }
                                    );

                                await bot.SendTextMessageAsync(message.Chat.Id, "Hmmmm... What should I do?..!", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0, keyboard);
                            }
                        }
                        else if ((message.Text[0] >= 'а' && message.Text[0] <= 'я') || (message.Text[0] >= 'А' && message.Text[0] <= 'Я'))
                        {
                            await bot.SendTextMessageAsync(message.Chat.Id, "I'm too lazy to learn russian, sorry...",
                                                           replyToMessageId : message.MessageId);
                        }
                        else
                        {
                            AIMLbot.Request r   = new AIMLbot.Request(message.Text, us, lazy);
                            AIMLbot.Result  res = lazy.Chat(r);

                            await bot.SendTextMessageAsync(message.Chat.Id, res.Output,
                                                           replyToMessageId : message.MessageId);
                        }
                    }
                };

                bot.StartReceiving();
            }
            catch (Telegram.Bot.Exceptions.ApiRequestException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #19
0
 public void testSetAndCondition()
 {
     this.mockRequest = new Request("TEST SET AND CONDITION", this.mockUser, this.mockBot);
     this.mockResult = this.mockBot.Chat(this.mockRequest);
     Assert.AreEqual("End value: 1.", this.mockResult.RawOutput);
 }
Beispiel #20
0
 public void testConstructor()
 {
     this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest);
     Assert.AreEqual("This is a test", this.mockResult.RawInput);
 }
Beispiel #21
0
        void Self_IM(object sender, InstantMessageEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            // Every event coming from a different thread (almost all of them, most certanly those
            // from libomv) needs to be executed on the GUI thread. This code can be basically
            // copy-pasted on the begining of each libomv event handler that results in update
            // of any GUI element
            //
            // In this case the IM we sent back as a reply is also displayed in the corresponding IM tab
            if (Instance.MainForm.InvokeRequired)
            {
                Instance.MainForm.BeginInvoke(
                    new MethodInvoker(
                        delegate()
                {
                    Self_IM(sender, e);
                }
                        ));
                return;
            }

            // We need to filter out all sorts of things that come in as a instante message
            if (e.IM.Dialog == InstantMessageDialog.MessageFromAgent && // Message is not notice, inv. offer, etc etc
                !Instance.Groups.ContainsKey(e.IM.IMSessionID) &&  // Message is not group IM (sessionID == groupID)
                e.IM.BinaryBucket.Length < 2 &&                  // Session is not ad-hoc friends conference
                e.IM.FromAgentName != "Second Life" &&           // Not a system message
                Alice.isAcceptingUserInput                       // Alice bot loaded successfully
                )
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.IM.FromAgentName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.IM.FromAgentName];
                        }
                        else
                        {
                            user = new User(e.IM.FromAgentName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.IM.FromAgentName));
                            AliceUsers[e.IM.FromAgentName] = user;
                        }
                        AIMLbot.Request req = new Request(e.IM.Message, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string msg          = res.Output;
                        if (msg.Length > 1000)
                        {
                            msg = msg.Substring(0, 1000);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(3));
                        }
                        Instance.Netcom.SendIMStartTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.Netcom.SendIMStopTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (Instance.MainForm.InvokeRequired)
                        {
                            Instance.MainForm.BeginInvoke(new MethodInvoker(() => Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID)));
                        }
                        else
                        {
                            Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID);
                        }
                    }
                });
            }
        }
Beispiel #22
0
        void Self_ChatFromSimulator(object sender, ChatEventArgs e)
        {
            // We ignore everything except normal chat from other avatars
            if (!Enabled || e.SourceType != ChatSourceType.Agent || e.FromName == Client.Self.Name || e.Message.Trim().Length == 0)
            {
                return;
            }

            bool parseForResponse = Alice != null && Alice.isAcceptingUserInput && Enabled;

            if (parseForResponse && respondRange >= 0)
            {
                parseForResponse = Vector3.Distance(Client.Self.SimPosition, e.Position) <= respondRange;
            }
            if (parseForResponse)
            {
                parseForResponse = respondWithoutName || e.Message.ToLower().Contains(FirstName(Client.Self.Name).ToLower());
            }


            if (parseForResponse)
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        string msg = e.Message.ToLower();
                        msg        = msg.Replace(FirstName(Client.Self.Name).ToLower(), "");
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.FromName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.FromName];
                        }
                        else
                        {
                            user = new User(e.FromName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.FromName));
                            AliceUsers[e.FromName] = user;
                        }

                        Client.Self.Movement.TurnToward(e.Position);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(1000 + 1000 * rand.Next(2));
                        }
                        if (!Instance.State.IsTyping)
                        {
                            Instance.State.SetTyping(true);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.State.SetTyping(false);
                        AIMLbot.Request req = new Request(msg, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string outp         = res.Output;
                        if (outp.Length > 1000)
                        {
                            outp = outp.Substring(0, 1000);
                        }

                        ChatType useChatType = ChatType.Normal;
                        if (shout2shout && e.Type == ChatType.Shout)
                        {
                            useChatType = ChatType.Shout;
                        }
                        else if (whisper2whisper && e.Type == ChatType.Whisper)
                        {
                            useChatType = ChatType.Whisper;
                        }
                        Client.Self.Chat(outp, 0, useChatType);
                    }
                });
            }
        }
Beispiel #23
0
 public void testRecursiveBlockCondition()
 {
     this.mockRequest = new Request("test block recursive call", this.mockUser, this.mockBot);
     this.mockResult = this.mockBot.Chat(this.mockRequest);
     Assert.AreEqual("Test passed.", this.mockResult.RawOutput);
 }
Beispiel #24
0
 public void testSetAndCondition()
 {
     this.mockRequest = new Request("TEST SET AND CONDITION", this.mockUser, this.mockBot);
     this.mockResult  = this.mockBot.Chat(this.mockRequest);
     Assert.AreEqual("End value: 1.", this.mockResult.RawOutput);
 }
Beispiel #25
0
 public void testConstructor()
 {
     mockResult = new Result(this.mockUser, this.mockBot, mockRequest);
     Assert.Equal("This is a test", mockResult.RawInput);
 }