forked from isaacs/node-eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.js
42 lines (35 loc) · 763 Bytes
/
repl.js
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
var readline = require('readline')
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl._prompt = '> '
var ElizaBot = require('./elizabot.js')
var eliza = new ElizaBot
eliza.memSize = 1024
function say (line) {
console.log('ELIZA: ' + line)
process.stdout.write(rl._prompt)
}
rl.on('line', function (line) {
line = line.trim()
if (!line) return
// user asked a question
if (line === '.reset') {
console.log(eliza.getFinal())
eliza.reset()
say(eliza.getInitial())
process.stdout.write(rl._prompt)
return
}
if (line === '.quit') {
process.exit()
return
}
var reply = eliza.transform(line)
say(reply)
if (eliza.quit) {
process.exit()
}
})
say(eliza.getInitial())