Beispiel #1
0
        /// <summary>
        /// When Enter is clicked, many operations happen.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Enter_Click(object sender, EventArgs e)
        {
            // Output user message
            OutputChat.AppendText("User: "******"\r\n" +
                                  "--------------------------------------------------------------------------------------------------------\r\n");

            // Add convo to history
            tempText.Add(InputChat.Text);
            historyIndex++;

            // Refresh Chatbox
            InputChat.Text = "";
            prevIndex      = historyIndex;
            OutputChat.Refresh();
            InputChat.Refresh();

            // Call Chakbot to respond
            ChakBot_Convo();
        }
Beispiel #2
0
        // ============================ END UI Features ================================


        // ============================ Chakbot Settings ================================
        /// <summary>
        /// Robot Response
        /// </summary>
        private async void ChakBot_Convo()
        {
            // Delay for aesthetics
            for (int i = 0; i < rnd.Next(1, 2); i++)
            {
                TypingDisplay.Text = "ChakBot is typing.";
                await Task.Delay(400);

                TypingDisplay.Text = "ChakBot is typing..";
                await Task.Delay(400);

                TypingDisplay.Text = "ChakBot is typing...";
                await Task.Delay(400);
            }

            if (tempText[historyIndex - 1] == "//help")
            {
                OutputChat.AppendText("ChakBot: " +
                                      "List of functions\r\n" +
                                      "====================================================\r\n" +
                                      "//clear\t| Clear the messages on screen\r\n" +
                                      "//time\t| Display the current time\r\n" +
                                      "teach=\t| Teach chakbot (root>message>corres>message)\r\n" +
                                      "e;n=\t| Encrypt by shifting n times\r\n" +
                                      "d;n=\t| Decrypt by shifting n times\r\n" +
                                      "morse=\t| Encrypr/decrypt message into morse code\r\n" +
                                      "cal=\t| Calculate\r\n" +
                                      "convert=\t| Convert units (#unit>unit)\r\n" +
                                      "====================================================\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//clear")
            {
                OutputChat.Clear();
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//time")
            {
                OutputChat.AppendText("ChakBot:\r\n >>> " +
                                      DateTime.Now.ToString() + " EST\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//brain")
            {
                System.IO.StreamReader read = new System.IO.StreamReader(PATH);

                // Read line and put into list
                string line;
                string message = "";

                while ((line = read.ReadLine()) != null)
                {
                    message += line + "\r\n";
                    message += "---\r\n";
                }

                read.Close();
                OutputChat.AppendText(message + "\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1].Contains("="))
            {
                if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "teach=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          teach_chakbot(tempText[historyIndex - 1].Substring(6,
                                                                                             tempText[historyIndex - 1].Length - 6), PATH + "/brain.txt") + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf(';') + 1).ToLower() == "e;" ||
                         tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf(';') + 1).ToLower() == "d;")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          chakbot_en_de(tempText[historyIndex - 1]) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "mc=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          MorseCode(tempText[historyIndex - 1].Substring(3, tempText[historyIndex - 1].Length - 3)) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "cal=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          Calculate(tempText[historyIndex - 1].Substring(4, tempText[historyIndex - 1].Length - 4)) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "convert=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          Convert(tempText[historyIndex - 1].Substring(8, tempText[historyIndex - 1].Length - 8)) + SEP);
                    TypingDisplay.Text = "";
                }
                else
                {
                    OutputChat.AppendText("ChakBot: " +
                                          "Please check your syntax." + SEP);
                    TypingDisplay.Text = "";
                }
            }
            else
            {
                OutputChat.AppendText("ChakBot: " +
                                      getMessage(tempText[historyIndex - 1]) + SEP);
                TypingDisplay.Text = "";
            }
        }