-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcli.js
More file actions
53 lines (43 loc) · 1.25 KB
/
cli.js
File metadata and controls
53 lines (43 loc) · 1.25 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
51
52
53
#!/usr/bin/env node
var pkg = require('./package.json');
var Surly = require('./src/Surly');
var conf = require('rc')('surly2', {
brain: '', b: '',
help: false,
version: false
});
const debug = require('debug')('surly2');
var options = {
brain: conf.b || conf.brain || __dirname + '/data/aiml',
help: conf.help || conf.h,
version: conf.version,
};
var prompt = 'You: ';
if (options.help) {
console.log('Surly chat bot command line interface\n\n' +
'Options: \n' +
' -b, --brain AIML directory (aiml/)\n' +
' --help Show this help message\n' +
' --version Show version number');
process.exit();
}
if (options.version) {
console.log(pkg.version);
process.exit();
}
var bot = new Surly({
brain: options.brain
});
console.log('Surly: Hello! Type quit to quit or /help for unhelpful help.');
process.stdout.write(prompt);
process.stdin.addListener('data', function (d) {
var sentence = d.toString().substring(0, d.length - 1);
if (sentence === 'quit' || sentence === 'exit') {
console.log('Yeah, fuck off.');
process.exit(0);
}
bot.talk(sentence, function (err, response) {
console.log('Surly: ' + response);
process.stdout.write(prompt);
});
});