Example #1
0
        //AB & LE & TB - All functionality that occurs when the send button is pressed.
        private void SendButton_Click(object sender, EventArgs e)
        {
            string[] UserLines = new string[4];
            string[] BotLines  = new string[4];

            //AB - Deals with the users message being sent.
            //AB - Handles an empty message box.
            if (string.IsNullOrWhiteSpace(UserMessageBox.Text))
            {
                MessageBox.Show("Please enter a message to send.");
            }

            else
            {
                //AB - Resets character counter upon pressing send.
                CharCount1Label.Text = "   0";
                CharCount1Label.Refresh();

                //AB & ABo - Method call to the lineSplitter function, that splits long messages into separate lines and outputs them.
                lineSplitter(UserMessageBox.Text, UserLines, "You");

                //AB - If the list box is filled, this scroll the list box down to the most recently added item.
                ConversationBox.TopIndex = ConversationBox.Items.Count - 1;

                //AB - Sets the UserMessageBox to being empty.
                string userInput = UserMessageBox.Text;
                UserMessageBox.Text = null;

                //AB - Adds a delay time to represent the lag of the connection between hosts before showing 'Seen', indicating the message arrived.
                waitFunction(1500);
                label1.Text = "✔Seen";

                //LE & TB - Adds a delay with the Bot's response to allow for 'Reading Time'.
                isReading(userInput);

                //AB - Occurs when the bot is gossiping.
                if (AIMode == false)
                {
                    gossipGenerator();
                }

                //AB - Occurs when the bot is just involved in general conversation.
                if (AIMode == true)
                {
                    //AB - Takes user string and generates the response from the AIML knowledge base.
                    Request r   = new Request(userInput, Program.myUser, Program.myBot);
                    Result  res = Program.myBot.Chat(r);

                    //AB & ABo - Method call to the lineSplitter function, that splits long messages into separate lines and outputs them.
                    lineSplitterBot(res.Output, BotLines, "Marvin");
                }

                //AB - If the list box is filled, this scroll the list box down to the most recently added item.
                ConversationBox.TopIndex = ConversationBox.Items.Count - 1;
            }
        }
Example #2
0
        //AB & ABo - Event that occurs when the user tpyes in the UserMessageBox.
        private void UserMessageBox_KeyDown(object sender, KeyEventArgs e)
        {
            //AB - Boolean flag that indicates if the key pressed was a character of a digit.
            bool isCharOrDigit = char.IsLetterOrDigit((char)e.KeyCode);

            //AB & ABo - Pressing the enter key has same affect as pressing the send button.
            if (e.KeyCode == Keys.Enter)
            {
                SendButton.PerformClick();
                e.Handled = true;
            }

            if (e.KeyCode == Keys.F1)
            {
                if (AIMode == false)
                {
                    AIMode = true;
                }

                else
                {
                    AIMode = false;
                }
            }

            //AB - Performs a decrease of the count when the backspace or enter key is pressed.
            if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
            {
                //AB - Updates the count display, with the correct formatting for a 1 digit count.
                if (UserMessageBox.Text.Length + 1 > 1 && UserMessageBox.Text.Length + 1 <= 9)
                {
                    CharCount1Label.Text = "   " + Convert.ToString(UserMessageBox.Text.Length - 1);
                    CharCount1Label.Refresh();
                }

                //AB - Updates the count display, with the correct formatting for a 2 digit count.
                if (UserMessageBox.Text.Length + 1 >= 10 && UserMessageBox.Text.Length + 1 <= 99)
                {
                    CharCount1Label.Text = "  " + Convert.ToString(UserMessageBox.Text.Length - 1);
                    CharCount1Label.Refresh();
                }

                //AB - Updates the count display, with the correct formatting for a 3 digit count.
                if (UserMessageBox.Text.Length + 1 >= 100 && UserMessageBox.Text.Length + 1 <= 150)
                {
                    CharCount1Label.Text = Convert.ToString(UserMessageBox.Text.Length - 1);
                    CharCount1Label.Refresh();
                }
            }

            //AB - Performs an increase of the count when a alphanumeric character is pressed.
            if (isCharOrDigit == true | e.KeyCode == Keys.Space)
            {
                //AB - Updates the count display, with the correct formatting for a 1 digit count.
                if (UserMessageBox.Text.Length + 1 <= 9)
                {
                    CharCount1Label.Text = "   " + Convert.ToString(UserMessageBox.Text.Length + 1);
                    CharCount1Label.Refresh();
                }

                //AB - Updates the count display, with the correct formatting for a 2 digit count.
                if (UserMessageBox.Text.Length + 1 >= 10 && UserMessageBox.Text.Length + 1 <= 99)
                {
                    CharCount1Label.Text = "  " + Convert.ToString(UserMessageBox.Text.Length + 1);
                    CharCount1Label.Refresh();
                }

                //AB - Updates the count display, with the correct formatting for a 3 digit count.
                if (UserMessageBox.Text.Length + 1 >= 100 && UserMessageBox.Text.Length + 1 <= 150)
                {
                    CharCount1Label.Text = Convert.ToString(UserMessageBox.Text.Length + 1);
                    CharCount1Label.Refresh();
                }
            }
        }