Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- listBox1.Items.Add(string.Join(Environment.NewLine, "BakaBot: Oh no, you are back again" ));
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string insertText = textBox2.Text;
- if (textBox2.Text != null)
- {
- listBox1.Items.Add(string.Join(Environment.NewLine, "User: " + insertText));
- }
- string inputCAPS = insertText.ToLower();
- List<string> outputs = letaSvar(inputCAPS);
- foreach (string output in outputs)
- {
- listBox1.Items.Add(string.Join(Environment.NewLine, "BakaBot: " + output));
- }
- textBox2.Text = null;
- string input = textBox2.Text;
- try
- {
- String str = "server=localhost;database=chattbott;UID=root;password=";
- String query = "select * from chattbott";
- SqlConnection con = new SqlConnection(str);
- SqlCommand cmd = new SqlCommand(query, con);
- con.Open();
- DataSet ds = new DataSet();
- MessageBox.Show("connect with sql server");
- con.Close();
- }
- catch (Exception es)
- {
- MessageBox.Show(es.Message);
- }
- }
- Keywords[] Nyckelord = new Keywords[] {
- new Keywords("hello", new string[] { }),
- new Keywords("how", new string[] { "how are", "whats up", "hows it", "what up" }),
- new Keywords("who", new string[] { "who", "what", "are you" }),
- new Keywords("sorry", new string[] {"my bad", "pardon", "excuse", "sorry"})
- };
- public List<string> brytnerFråga(string Fråga)
- {
- //string[] searchwords = new string[] {"Hi" }
- List<string> Words = new List<string>();
- foreach (Keywords item in Nyckelord)
- {
- string answer = item.Search(Fråga);
- if (answer != "")
- {
- Words.Add(answer);
- }
- }
- if (Words.Count != 0)
- {
- return Words;
- }
- return null;
- }
- public List<string> letaSvar(string Fråga)
- {
- List<string> Delsvar = new List<string>();
- List<string> Frågor = brytnerFråga(Fråga);
- foreach (Record item in Databas)
- {
- if (Frågor == null)
- {
- break;
- }
- foreach (string Delfråga in Frågor)
- {
- if (item.GetInput == Delfråga)
- {
- Delsvar.Add(item.GetAOutput);
- }
- }
- }
- if (Delsvar.Count != 0)
- {
- return Delsvar;
- }
- Delsvar.Add("Are you too dumb to speak properly?");
- return Delsvar;
- }
- Record[] Databas = new Record[] {
- new Record("hello",new string[]{"Why should I greet you? Idiot","Have I allowed you to speak with me? The answer is no","... Oh you were standing there. Please go away" } ),
- new Record("how",new string[]{"Why would I care to explain anything for an idiot", "You are too dumb to get my knowledge", "Stop asking me dumb questions"} ),
- new Record("who",new string[]{"Do I look like an encyklopedia?", "A person, idiot", "And why would I answer that dumb question?" } ),
- new Record("sorry",new string[]{"Atleast you can admit to being an idiot", "Apology not accepted", "Now you know your rightful position"})
- };
- struct Keywords
- {
- string type;
- string[] synonyms;
- public string Search(string input)
- {
- string[] Frågedelar = input.Split(' ');
- string formerpart = "";
- foreach (string item in synonyms)
- {
- string[] items = item.Split(' ');
- foreach (string part in Frågedelar)
- {
- if (part == item)
- {
- return type;
- }
- else
- {
- if (items.Length != 1)
- if (formerpart == items[0] && part == items[1])
- {
- return type;
- }
- }
- formerpart = part;
- }
- }
- return "";
- }
- public Keywords(string type, string[] synonyms)
- {
- this.type = type;
- this.synonyms = synonyms;
- }
- }
- struct Record
- {
- static string formerkeyword = "";
- static string formeranswer = "";
- string input;
- string[] outputs;
- public string GetInput
- {
- get
- {
- formerkeyword = input;
- return input;
- }
- }
- public string GetAOutput
- {
- get
- {
- string output = outputs[RandAnswer.Next(outputs.Length)];
- if (output == formeranswer)
- {
- output = outputs[RandAnswer.Next(outputs.Length)];
- }
- formeranswer = output;
- return output;
- }
- }
- public Random RandAnswer;
- public Record(string input, string[] outputs)
- {
- RandAnswer = new Random();
- this.input = input;
- this.outputs = outputs;
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged_1(object sender, EventArgs e)
- {
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- listBox1.Items.Clear();
- listBox1.Items.Add(string.Join(Environment.NewLine, "BakaBot: Oh no, you are back again"));
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement