-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrosie.js
99 lines (77 loc) · 3.15 KB
/
rosie.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
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
/****************************************************
O))))))) O)))) O)) O) O))O))))))))
O)) O)) O)) O)) O)) O))O))O))
O)) O)) O)) O)) O)) O))O))
O) O)) O)) O)) O)) O))O))))))
O)) O)) O)) O)) O)) O))O))
O)) O)) O)) O)) O)) O))O))O))
O)) O)) O)))) O)) O) O))O))))))))
Copy config.sample.js to config.js and fill it out
then type `node rosie.js` to run
****************************************************
Don't change anything beyond here fam
***************************************************/
var chalk = require('chalk'),
irc = require('irc'),
events = require('events'),
http = require('http'),
eventEmitter = global.eventEmitter = new events.EventEmitter,
package = require('./package.json'),
Q = global.Q = require('q'),
NOOP = function(){};
try {
var config = require('./config');
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') return console.log(chalk.red('No config.js file found! Did you even read the README.md????'));
}
console.log(' ___ ____ ____________')
console.log(' / _ \\/ __ \\/ __/ _/ __/')
console.log(' / , _/ /_/ /\\ \\_/ // _/ ')
console.log('/_/|_|\\____/___/___/___/ v'+package.version);
process.chdir(__dirname);
global.rosie = {
version:package.version,
uptime:new Date(),
config:config
};
rosie = global.rosie;
(function() {
var deferred = Q.defer();
require('./core/models').initialize(config.orm, function(err, models) {
if (err) throw err;
global.rosie.models = models.collections;
console.log(chalk.green(Object.keys(models).length)+' models loaded');
deferred.resolve();
});
return deferred.promise;
}())
.done(function() {
require('./core/slack')(function() {
client = global.rosie.client = new irc.Client(
config.slack.team + '.irc.slack.com',
config.slack.user,
{
password: config.slack.password,
userName: config.slack.user,
autoConnect:false
});
console.log('Connecting to Slack...');
client.connect(999, function() {
eventEmitter.emit('rosie:connect');
console.log(chalk.green('Connected!'));
});
/* Raw logger */
if (config.logging.raw === true) client.addListener('raw', function(message) {
rosie.models.raw.create(message).exec(NOOP);
});
client.addListener('message', function(from, to, message) {
var eventName = 'message';
if (message.substr(0,config.bot.trigger.length) === config.bot.trigger) eventName = message.split(' ')[1];
if (to === config.slack.user) eventName = message.split(' ')[0];
if (!from) from = arguments[3].prefix.split('!')[0].replace('_', ' ');
if (config.logging.chat === true) rosie.models.chat.create({from:from, to:to, message:message}).exec(function(){});
eventEmitter.emit('rosie:'+eventName, from, to, eventName === 'message' ? message : message.substr(eventName.length).trim());
});
require('./triggers/version')();
});
});