-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
66 lines (57 loc) · 1.72 KB
/
bot.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
from bottle import run, route, request, redirect
import aiml
from random import choice
botbrain = aiml.Kernel()
botbrain.learn('yulan.aiml')
exception_brainmatrix = ['\n','\t']
default_excuses = [':)',
'gatau :P',
':3',
'ulan gatau, ajarin ulan dong',]
with open('yulan.aiml', 'r') as readbrain:
brains = readbrain.readlines()
brain_matrix = []
for contents in brains:
if contents not in exception_brainmatrix:
brain_matrix.append(contents)
knowledge = '-'.join(brain_matrix)
questions = []
@route('/hello')
def VIEW():
return '''
<html>
<title>ulan - aiml + python + bottle</title>
<h1>Ulan</h1>
<hr>
<b> Ulan (baca: yu-lan) is a chatterbot based on yulanyulianty's answers on her ask.fm </b>
<hr>
<br></br>
<p> you just asked {} </p>
<form action="/login" method="post">
ask: <input name="ask" type="text"/>
<input value="tanya" type="submit" />
<br></br>
<p> status: </p>
<p> current brain matrix: {} </p>
<p> current AIML Brain knowledge(s)</p>
<p> {} </p>
</html>
'''.format(questions,len(knowledge), knowledge)
@route('/ulan')
def ulanmain():
pass
@route('/login', method='POST')
def AIML():
ask = request.forms.get('ask')
if ask != None or ask != "":
questions.append(ask)
try:
ans = botbrain.respond(ask)
except:
ans = choice(default_excuses)
ask_template = '<p> you just asked: {}'.format(ask)
respond_template = '<p> her answer: {}'.format(ans)
return ask_template, respond_template
redirect('http://localhost:8080/hello')
return "You asked nothing!"
run(host='localhost', port=8080, debug=True)