Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();
            this.Text = "Cleverbot Example";

            Label_Status.Text = "";

            Textbox_Input.Text      = defaultInputText;
            Textbox_Input.ForeColor = Color.Gray;

            Textbox_Input.GotFocus += (s, e) =>
            {
                if (Textbox_Input.Text == defaultInputText)
                {
                    Textbox_Input.Text = "";
                }
                Textbox_Input.ForeColor = Color.Black;
            };

            Textbox_Input.LostFocus += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(Textbox_Input.Text))
                {
                    Textbox_Input.Text = defaultInputText;
                }
                Textbox_Input.ForeColor = Color.Gray;
            };

            Textbox_Input.KeyDown += (s, e) =>
            {
                if (e.KeyData == Keys.Enter)
                {
                    if (string.IsNullOrWhiteSpace(Textbox_Input.Text))
                    {
                        return;
                    }

                    cleverbot.GetResponseAsync(Textbox_Input.Text, result =>
                    {
                        Label_Status.Text = "";
                        SendMessage(result.Response, "Cleverbot");
                    });

                    Label_Status.Text = "Cleverbot is typing...";
                    SendMessage(Textbox_Input.Text, "You");
                    Textbox_Input.Text = "";
                }
            };
        }
Exemplo n.º 2
0
        public async Task CleverbotLoop()
        {
            Cleverbot cleverbot = new Cleverbot("your-api-key");

            Console.WriteLine("Hello in the Cleverbot.Net test app, please type your message.\n");

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Gray;

                string msg = Console.ReadLine();

                cleverbot.GetResponseAsync(msg, x =>
                {
                    Console.CursorLeft = 0;

                    Console.ForegroundColor = ConsoleColor.White;

                    Console.WriteLine(x.Response);
                });

                Console.Write("...");
            }
        }