forked from sdwilsh/tree-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.js
34 lines (27 loc) · 801 Bytes
/
console.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
var channels = require("./channels");
var updater = require("./updater");
var session = require("./sessionrestore");
var kChannelName = '<console>';
updater.restart = function () {
console.log("It's less awkward if I just exit");
process.exit()
}
var backend = {
say: console.log,
pm: console.log,
isAuthorizedUser: function (who) { return true; },
channelStateChanged: session.updateChannelState.bind(session, kChannelName),
};
session.restore(function (name, cb) {
if (name === kChannelName) {
return cb(backend);
}
});
var channel = channels.get(kChannelName);
if (channel === undefined) {
channel = channels.add(kChannelName, backend);
}
process.stdin.resume();
process.stdin.on('data', function (text) {
channel.handleCommand('', text.toString('utf8').trim());
});