forked from TheSharks/WildBeast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (56 loc) · 1.99 KB
/
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
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
require('dotenv').config()
global.logger = require('./src/internal/logger')
global.i18n = require('./src/internal/i18n')
require('./src/internal/secrets-loader')
require('./src/internal/check-env')
global.logger.log('Beginning startup sequence...')
require('./src/internal/version-check')
const Eris = require('eris')
const Events = require('./src/internal/directory-loader')('./src/events')
const dogstats = require('./src/statistics/dogstats-legacy')
require('./src/internal/k8s-autoscale').then(x => {
global.logger.log(`Scaling known. Total: ${x.total}, mine: ${x.mine}`)
const bot = new Eris(process.env.BOT_TOKEN, {
restMode: true,
maxShards: x.total,
firstShardID: x.mine,
lastShardID: x.mine
})
global.bot = bot
bot._ogEmit = bot.emit
bot.on('rawWS', () => {}) // noop to force eris to fire rawWS
bot.emit = function emit () {
this._anyListeners.forEach(listener => listener.apply(this, [arguments]))
return this._ogEmit.apply(this, arguments)
}
bot.onAny = function onAny (func) {
if (!this._anyListeners) this._anyListeners = []
this._anyListeners.push(func)
}
bot.on('debug', global.logger.debug)
bot.on('error', (e) => {
if (!(e instanceof Error)) global.logger.error(e.error)
else global.logger.error(e)
})
if (process.env.HOTSHOTS_HOST) {
global.logger.warn("Using Dogstats in this way is deprecated, it's recommended to switch to a different stats aggregator")
setInterval(() => dogstats.statsHook(bot), 1000)
}
bot.onAny((ctx) => {
dogstats.eventHook(ctx[0])
if (Events[ctx[0]]) {
Events[ctx[0]](Array.from(ctx).slice(1))
}
})
bot.connect().then(() => {
require('./src/internal/bezerk')
})
})
process.on('warn', global.logger.warn)
process.on('unhandledRejection', (err) => {
global.logger.error(err)
})
process.on('uncaughtException', (err) => {
// probably not the most stylish way to handle this, but it works
global.logger.error(err, true) // we're exiting here, uncaughts are scary
})