@pythonb5/

chatlib

Python

A tiny library for little chatbots. - https://github.com/python-b5/chatlib.py

fork
loading
Files
  • main.py
  • chatlib.py
  • README
  • test.py
main.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Test bot
# by python-b5
#
# A test chatbot for chatlib.

import chatlib
import time
import replit

replit.clear()

bot = chatlib.Bot("Other")

bot.main.add_response("What?")
bot.main.add_response("Sorry, didn't catch that...")

hello = bot.create_path()
hello.add_keyword("hello")
hello.add_keyword("hi")
hello.add_response("Hello :)[%b]What's up?")
hello.add_response("Hi!")

goodbye = bot.create_path()
goodbye.add_keyword("goodbye")
goodbye.add_keyword("bye")
goodbye.add_response("Bye...")
goodbye.add_response("See you!")

whatsup = bot.create_path()
whatsup.add_keyword("whats up")
whatsup.add_keyword("what's up")
whatsup.add_keyword("what is up")
whatsup.add_response("Nothing much.")
whatsup.add_response("Not much, really.")

howareyou = bot.create_path()
howareyou.add_keyword("how are you")
howareyou.add_keyword("are you doing well")
howareyou.add_response("I'm doing pretty well, you?")
howareyou.add_response("I'm fine, are you?")

howareyou_bad = bot.create_path(howareyou)
howareyou_bad.add_keyword("bad")
howareyou_bad.add_keyword("awful")
howareyou_bad.add_keyword("terrible")
howareyou_bad.add_keyword("not good")
howareyou_bad.add_keyword("not great")
howareyou_bad.add_response("Don't worry... I'm sure you'll feel better soon!")
howareyou_bad.add_response("Sorry to hear that...")

howareyou_good = bot.create_path(howareyou)
howareyou_good.add_keyword("good")
howareyou_good.add_keyword("great")
howareyou_good.add_keyword("amazing")
howareyou_good.add_keyword("awesome")
howareyou_good.add_response("That's great!")
howareyou_good.add_response("Glad to hear it!")

you = bot.create_path()
you.add_keyword("you")
you.exclude_keyword("how are")
you.exclude_keyword("doing well")
you.add_response("What about me?")
you.add_response("Oh, alright.")
you.add_response("Okay...")

ok = bot.create_path()
ok.add_keyword("o.k.")
ok.add_keyword("o.k")
ok.add_keyword("ok")
ok.add_keyword("okay")
ok.add_keyword("yeah")
ok.add_keyword("yes")
ok.add_response("Yeah...")
ok.add_response("Yeah.")

metoo = bot.create_path()
metoo.add_keyword("me too")
metoo.add_response("Oh, cool")
metoo.add_response("Alright :)")

negative = bot.create_path()
negative.add_keyword("bad")
negative.add_keyword("awful")
negative.add_keyword("terrible")
negative.add_keyword("not good")
negative.add_keyword("not great")
negative.add_keyword("uncool")
negative.add_response("Hmm...alright.")
negative.add_response("That's a little negative. :(")

positive = bot.create_path()
positive.add_keyword("good")
positive.add_keyword("great")
positive.add_keyword("amazing")
positive.add_keyword("awesome")
positive.add_keyword("fantastic")
positive.add_keyword("wonderful")
positive.add_keyword("cool")
positive.add_response("I'm glad you think that.. :)")
positive.add_response("Fantastic! ;)")
positive.add_response("Sure is...")
positive.add_response("That's good :)")

whatis = bot.create_path()
whatis.add_keyword("what is [%s]")
whatis.add_keyword("whats [%s]")
whatis.add_keyword("what's [%s]")
whatis.add_keyword("do you know what [%s] is")
whatis.add_keyword("tell me what [%s] is")
whatis.add_response("I don't know what [%0] is...")
whatis.add_response("Sorry, I'm not sure what that is...")

whois = bot.create_path()
whois.add_keyword("who is [%s]")
whois.add_keyword("whos [%s]")
whois.add_keyword("who's [%s]")
whois.add_keyword("do you know who [%s] is")
whois.add_keyword("tell me who [%s] is")
whois.add_response("I don't know who [%0] is...")
whois.add_response("I don't know :(")

whatare = bot.create_path()
whatare.add_keyword("what are [%s]")
whatare.add_keyword("do you know what [%s] are")
whatare.add_keyword("tell me what [%s] are")

bot.set_username(str(input("Username: ")))
replit.clear()

print("Welcome,", bot.username.value + "!")
print()

while True:
    r = input(bot.username.value + ": ")
    response = bot.get_response(r)
    time.sleep(len(response) / 4)
    print()
    print(bot.name.value + ":", response)
    
    while bot.pending():
        response = bot.get_response()
        time.sleep(len(response) / 4)
        print()
        print(bot.name.value + ":", response)
    
    print()