-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (43 loc) · 1.21 KB
/
main.go
File metadata and controls
51 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
// Define simple responses for specific inputs
func getResponse(input string) string {
input = strings.ToLower(strings.TrimSpace(input))
switch input {
case "hello", "hi":
return "Hello! How can I help you today?"
case "how are you?":
return "I'm just a bunch of code, but I'm doing fine!"
case "what is your name?":
return "I'm a simple Go chatbot."
case "bye", "exit":
return "Goodbye! Have a great day!"
default:
return "Sorry, I don't understand that. Can you try asking something else?"
}
}
func main() {
fmt.Println("Welcome to GoBot! Type something to begin (type 'exit' to quit).")
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print("You: ")
if !scanner.Scan() {
break
}
input := scanner.Text()
if strings.ToLower(strings.TrimSpace(input)) == "exit" {
fmt.Println("GoBot: Goodbye!")
break
}
response := getResponse(input)
fmt.Println("GoBot:", response)
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Error reading input:", err)
}
}