This repository was archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
47 lines (39 loc) · 1.75 KB
/
bot.js
File metadata and controls
47 lines (39 loc) · 1.75 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
let moment = require('moment'),
storyboard = require('storyboard'),
fs = require('fs');
const config = require('./lib/load_config.js'),
langfile = require('./langfile.js');
let plugged = require('./lib/client'),
redis = require('./lib/db/redis_db'),
story = storyboard.mainStory;
storyboard.config({filter: `*:${config.options.loglevel}`});
storyboard.addListener(require('storyboard/lib/listeners/console').default); //eslint-disable-line global-require
story.info(`Starting plugbot version ${require('./package.json').version}`); //eslint-disable-line global-require
moment.locale(langfile.momentLocale);
//noinspection JSUnresolvedFunction
redis.del('user:roles');
redis.exists('meta:data:staff:active').then(ex => {
if (ex === 0) redis.set('meta:data:staff:active', 1);
});
fs.readdir('./lib/eventhandlers', (err, files) => {
if (err) {
story.fatal('Cannot load eventhandlers.', {attach: err});
process.exit(1);
} else {
files.forEach(file => {
try {
let h = require(`./lib/eventhandlers/${file}`); //eslint-disable-line global-require
if (Array.isArray(h.event)) {
h.event.forEach(event => {
plugged.on(event, h.handler);
});
} else plugged.on(h.event, h.handler);
story.debug('EventHandlers', `Loaded Handler for Event ${Array.isArray(h.event) ? h.event.join() : h.event}`);
} catch (e) {
story.error(`Failed to load eventhandler ${file}`, {attach: e});
process.exit(1);
}
});
}
});
module.exports = {plugged, app: (config.web.enabled ? require('./web/index').app : null)}; //eslint-disable-line global-require