-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
58 lines (48 loc) · 1.32 KB
/
start.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const dotenv = require('dotenv')
dotenv.load()
const vorpal = require('vorpal')()
const { getState, subscribe, dispatch } = require('./store')
const Actions = require('./action-creators')
const {
predictSequence,
learn,
login,
haveYouSeen,
recurseSeen,
predict } = require('./action-creators')
const toPairs = require('lodash.topairs')
let messageRef
subscribe(() => {
const { message, command, seeding, shouldContinue } = getState()
if (message !== messageRef) {
command.log(message)
messageRef = message
}
})
vorpal
.command('login <username>', 'identifies user')
.action(function (args, done) {
dispatch(login(this, args.username, done))
})
vorpal
.command('learn', 'movie-bot learns the movies you like')
.action(function (args, callback) { dispatch(learn()) })
vorpal
.command('predict', 'movie-bot tries to predict movies that you will like but have not seen')
.action(function (args, callback) {
dispatch(predictSequence())
})
vorpal
.command('search <title>', 'searches for a movie')
.action(function (args, cb) {
searchMovie(args.title, (err, results) => {
this.prompt(confirmMovie(results), (result) => {
this.log('seeding database...')
seedFromMovie(result.movieId, cb)
})
})
})
vorpal
.delimiter('>>')
.show()
.parse(process.argv)