-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1000 Bytes
/
index.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
/**
* Library dependencies
*/
const co = require('co');
const SlackBot = require('slackbots');
const { MongoClient } = require('mongodb');
/**
* Project modules
*/
const config = require('./config/secrets');
const logger = require('./util/logger');
const message = require('./lib/message');
const close = require('./lib/close');
const start = require('./lib/start');
/**
* Configurations
*/
const { token, mongoUrl, collectionName, adminUser, bot: { id, icon, name } } = config;
/**
* Run the slack bot
*/
co(function*() {
logger('[CONNECTING]: MongoClient');
const bot = new SlackBot({ token, name });
const db = yield MongoClient.connect(mongoUrl);
const collection = db.collection(collectionName);
logger('[CONNECTING]: SlackBot');
bot.on('start', start.bind(null, bot, adminUser, { icon_emoji: icon }));
bot.on('message', message.bind(null, bot, collection, { id, icon }));
bot.on('close', close.bind(null, bot, db));
}).catch( error => logger('[ERROR]', error) );