-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
134 lines (112 loc) · 3.61 KB
/
index.js
File metadata and controls
134 lines (112 loc) · 3.61 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
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
var vorpal = require('vorpal')(),
path = require('path'),
bole = require('bole'),
chalk = require('chalk');
var facebook = require('./src/facebook'),
facebookVorpal = require('./src/facebook-vorpal');
var Utils = require('./src/utils');
var Facebook = new facebook(vorpal);
var FacebookVorpal = new facebookVorpal(Facebook);
bole.output({
level: 'info',
stream: process.stdout
});
vorpal
.command('init', 'Initialize Facebook (login, etc...)')
.action(function(args, callback) {
Facebook
.init()
.then(callback)
.catch(e => { setTimeout(() => { throw e; callback(); }); });
});
vorpal
.command('threads [search]', 'Display threads/conversations')
.alias('t')
.option('-N <number>', 'Number of messages to load')
.action(function(args, callback) {
// Verify that the user is logged in
if (!Facebook.loggedin) {
this.log(chalk.bold.red('You must login before continuing.'));
this.log('Type', chalk.bold('init'), 'to login.\n');
return callback();
}
// Bind the log and prompt functions
FacebookVorpal.prompt = this.prompt.bind(this);
FacebookVorpal.print = this.log.bind(this);
// Get the search term (if any...)
var search = args.search;
var N = args.options.N;
// Prompt for a thread and print it!
FacebookVorpal
.promptThread(search)
.then(thread => FacebookVorpal.printThread(thread, N))
.then(callback)
.catch(e => { setTimeout(() => { throw e; callback(); }); });
});
vorpal
.command('send', 'Send a message')
.alias('s')
.action(function(args, callback) {
// Verify that the user is logged in
if (!Facebook.loggedin) {
this.log(chalk.bold.red('You must login before continuing.'));
this.log('Type', chalk.bold('init'), 'to login.\n');
return callback();
}
// Bind the log and prompt functions
FacebookVorpal.prompt = this.prompt.bind(this);
FacebookVorpal.print = this.log.bind(this);
FacebookVorpal
.promptMessage()
.then(callback)
.catch(e => { setTimeout(() => { throw e; callback(); }); });
});
vorpal
.command('clean', 'Clean the current window')
.alias('clear')
.action(function(args, cb) {
process.stdout.write('\u001B[2J\u001B[0;0f');
cb();
});
vorpal
.command('vim', 'Open VIM')
.alias('v')
.action(function(args, cb) {
Utils
.vimInput()
.then(data => {
this.log(data);
cb();
})
.catch(e => {
this.log(e);
cb();
});
});
vorpal
.command('messages', 'Debug messages')
.action(function(args, callback) {
// Bind the log and prompt functions
FacebookVorpal.prompt = this.prompt.bind(this);
FacebookVorpal.print = this.log.bind(this);
FacebookVorpal
.promptThread()
.then(thread => { this.log(JSON.stringify(thread, null, 4)); })
.then(callback)
.catch(e => { setTimeout(() => { throw e; callback(); }); });
});
vorpal
.delimiter('m $>')
.show();
/**
* Bind CTRL + L to clear the window terminal
*/
process.stdin.on('keypress', function(letter, key) {
if (key.ctrl === true && ['l', 'L'].indexOf(key.name) > -1) {
vorpal.exec('clean');
}
});
process.on('uncaughtException', function(err) {
// handle the error safely
console.log(err)
});