-
Notifications
You must be signed in to change notification settings - Fork 2
/
xi.js
50 lines (44 loc) · 1.19 KB
/
xi.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
/* XI - eXtensible Intelligence :P */
// load dependencies
var PubSub = require('pubsub-js');
var sugar = require('sugar');
var path = require('path');
// Initialize logger
var winston = require('winston');
var logfile = path.resolve(__dirname, 'logs/',
Date.create().format('{yyyy}-{MM}-{dd}')
+ '.log');
winston.add(winston.transports.File,
{
filename: logfile,
maxsize: 10000000,
maxFiles: 10000,
level: 'verbose'
});
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console,
{
colorize: true,
});
exports.logger = winston;
// Define standard communication channels, and functions
// to subscribe/publish to a channel
exports.channels = {
sensory: {
up: "_SENSORY_UP",
down: "_SENSORY_DOWN"
},
sentiment: "_SENTIMENT",
speak: "_SPEAK",
subscribe: function (channelName, callback) {
// TODO: process channel_name in some way?
return PubSub.subscribe(channelName, callback);
},
publish: function (channelName, data) {
// TODO: process data in some way?
PubSub.publish(channelName, data);
}
};
exports.speak = function(text, cb) {
exports.channels.publish(exports.channels.speak, {text:text, cb:cb});
};