コード例 #1
0
        private string showOutput(string message)
        {
            string replyMessage = null;

            if (!(string.IsNullOrWhiteSpace(message))) // Make sure the textbox isnt empty
            {
                // Store the Bot's Output by giving it our input.
                string outtt = bot.getOutput(message);
                replyMessage = outtt;

                //=========== Creates backup of chat from user and bot to the given location ============
                FileStream fs = new FileStream(@"chat.log", FileMode.Append, FileAccess.Write);
                if (fs.CanWrite)
                {
                    byte[] write = System.Text.Encoding.ASCII.GetBytes(message + Environment.NewLine + outtt + Environment.NewLine);
                    fs.Write(write, 0, write.Length);
                }
                fs.Flush();
                fs.Close();
            }
            return(replyMessage);
        }
コード例 #2
0
        private void showOutput()
        {
            if (!(string.IsNullOrWhiteSpace(InputTxt.Text)))      // Make sure the textbox isnt empty
            {
                SoundPlayer Send = new SoundPlayer("SOUND1.wav"); // Send Sound Effect
                SoundPlayer Rcv  = new SoundPlayer("SOUND2.wav"); // Recieve Sound Effect


                InputTxt.Text = InputTxt.Text.Replace("I am not smart enough to understand what the heck you just said, sorry.", "");
                InputTxt.Text = InputTxt.Text.Replace("I am not smart enough to understand what the heck you just said, sorry", "");
                InputTxt.Text = InputTxt.Text.Replace("I am not smart enough to understand what the heck you just said", "");
                InputTxt.Text = InputTxt.Text.Replace("\n", "");

                if (InputTxt.Text == "" || string.IsNullOrEmpty(InputTxt.Text) || InputTxt.Text.ToLower() == InputTxt.Text.ToUpper())
                {
                }
                else
                {
                    // Show the user message and play the sound

                    addInMessage(InputTxt.Text);
                    Send.Play();
                }

                // Store the Bot's Output by giving it our input.
                string outtt = bot.getOutput(InputTxt.Text);

                if (outtt.Length == 0)
                {
                    outtt = "I don't understand.";
                }


                // Hide the "Bot is typing.." text
                txtTyping.Hide();

                outtt = outtt.Replace("I am not smart enough to understand what the heck you just said, sorry.", "");
                outtt = outtt.Replace("I am not smart enough to understand what the heck you just said, sorry", "");
                outtt = outtt.Replace("I am not smart enough to understand what the heck you just said", "");
                outtt = outtt.Replace("\n", "");

                if (outtt == "" || string.IsNullOrEmpty(outtt) || outtt.ToLower() == outtt.ToUpper())
                {
                    addOutMessage("Bye");
                }


                if (outtt == "")
                {
                    //init();
                    WriteToLog();
                    return;
                }
                else
                {
                    lock (this)
                    {
                        WriteToLog("[Bot:" + outtt + ']');
                    }
                }

                // disable the chat box white the bot is typing to prevent user spam.
                InputTxt.Enabled = false;

                // Once the timer ends

                InputTxt.Enabled = true; // Enable Chat box

                // Show the bot message and play the sound
                addOutMessage(outtt);
                //Rcv.Play();

                // Text to Speech if enabled
                if (textToSpeech)
                {
                    reader.SpeakAsync(outtt);
                }

                InputTxt.Focus(); // Put the cursor back on the textbox

                /*
                 * outtt = user.getOutput(outtt);
                 * InputTxt.Text = outtt; //User types the text
                 */


                if (outtt == "" || string.IsNullOrEmpty(outtt) || outtt.ToLower() == outtt.ToUpper())
                {
                    //init();
                    WriteToLog();
                    return;
                }
                outtt         = user.getOutput(outtt);
                InputTxt.Text = outtt;
                outtt         = outtt.Replace("I am not smart enough to understand what the heck you just said, sorry.", "");
                outtt         = outtt.Replace("I am not smart enough to understand what the heck you just said, sorry", "");
                outtt         = outtt.Replace("I am not smart enough to understand what the heck you just said", "");
                if (outtt.ToLower().Contains("I am not smart enough to understand what the heck you just said, sorry".ToLower()))
                {
                    var v = 0;
                }

                lock (this)
                {
                    WriteToLog("[User:" + outtt + ']');
                }
                button1_Click(this.button1, new EventArgs());
            }
        }
コード例 #3
0
ファイル: ChatBot.cs プロジェクト: Alireza-Rah64/Myproject
        private void showOutput()
        {
            if (!(string.IsNullOrWhiteSpace(InputTxt.Text)))      // Make sure the textbox isnt empty
            {
                SoundPlayer Send = new SoundPlayer("SOUND1.wav"); // Send Sound Effect
                SoundPlayer Rcv  = new SoundPlayer("SOUND2.wav"); // Recieve Sound Effect

                // Show the user message and play the sound
                addInMessage(InputTxt.Text);
                Send.Play();

                // Store the Bot's Output by giving it our input.
                string outtt = bot.getOutput(InputTxt.Text);

                if (outtt.Length == 0)
                {
                    outtt = "I don't understand.";
                }

                //=========== Creates backup of chat from user and bot to the given location ============
                FileStream fs = new FileStream(@"chat.log", FileMode.Append, FileAccess.Write);
                if (fs.CanWrite)
                {
                    byte[] write = System.Text.Encoding.ASCII.GetBytes(InputTxt.Text + Environment.NewLine + outtt + Environment.NewLine);
                    fs.Write(write, 0, write.Length);
                }
                fs.Flush();
                fs.Close();
                //=======================================================================================

                // Make a Dynamic Timer to delay the bot's response to make it feel humanlike.
                var t = new Timer();

                // Time in milseconds - minimum delay of 1s plus 0.1s per character.
                t.Interval = 1000 + (outtt.Length * 100);

                // Show the "Bot is typing.." text
                txtTyping.Show();

                // disable the chat box white the bot is typing to prevent user spam.
                InputTxt.Enabled = false;

                t.Tick += (s, d) =>
                {
                    // Once the timer ends

                    InputTxt.Enabled = true; // Enable Chat box

                    // Hide the "Bot is typing.." text
                    txtTyping.Hide();

                    // Show the bot message and play the sound
                    addOutMessage(outtt);
                    Rcv.Play();

                    // Text to Speech if enabled
                    if (textToSpeech)
                    {
                        reader.SpeakAsync(outtt);
                    }

                    InputTxt.Focus(); // Put the cursor back on the textbox
                    t.Stop();
                };
                t.Start();          // Start Timer

                InputTxt.Text = ""; // Reset textbox
            }
        }
コード例 #4
0
        void TransactionProcess()
        {
            if (processNo == 0)
            {
                outtt = bot.getOutput(InputTxt.Text);
            }

            else if (processNo == 1)
            {
                CardNo = Convert.ToInt32(InputTxt.Text); trans.GetClientAccounts(CardNo); processNo = 2; outtt = bot.getOutput("PinNo");
            }
            else if (processNo == 2)
            { //enter account id
                pin = Convert.ToInt32(InputTxt.Text);
                if (trans.GetCardInfo(CardNo, pin))
                {
                    outtt     = bot.getOutput("TransType");
                    processNo = 3;
                }
                else
                {
                    outtt = "Wrong Account ID or Pin !";
                    //   outtt = "IsRegistered.";
                    processNo = 0;
                }
            }
            else if (processNo == 3)
            {
                outtt = bot.getOutput(InputTxt.Text);
                if (outtt == "D.")
                {
                    type = "Deposit";
                }
                else
                {
                    type = "Withdraw";
                }

                outtt     = bot.getOutput("DoTrans " + outtt[0]);
                processNo = 4;
            }
            else if (processNo == 4)
            {
                int amount = Convert.ToInt32(InputTxt.Text);
                int ret    = trans.makeTransaction(type, amount);
                if (ret == -1)
                {
                    outtt = "you can't withdraw more than your balance !";
                }
                else
                {
                    outtt     = "Transaction Done ! your new balance is : " + Convert.ToString(ret);
                    processNo = 0;
                }
            }
            // Store the Bot's Output by giving it our input.
            // string  = "HELLO";
            if (outtt == "IsRegistered.")
            {
                checkIfRegistered();
                outtt = bot.getOutput("BankerIs " + banker);
                if (banker != 'x')
                {
                    processNo = 1;
                }
            }
        }