-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitchblade.js
More file actions
66 lines (57 loc) · 1.98 KB
/
Copy pathSwitchblade.js
File metadata and controls
66 lines (57 loc) · 1.98 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { CommandClient } = require('eris')
const Loaders = require('../../loaders')
const { LoaderPriority } = require('../Loader.js')
const { readFileSync } = require('fs')
const winston = require('winston')
const chalk = require('chalk')
module.exports = class Switchblade extends CommandClient {
constructor(token, options, commandOptions) {
super(token, options, commandOptions)
this.initializeWinston()
this.start()
}
start() {
if (process.env.NODE_ENV !== 'production') console.log(readFileSync('bigtitle.txt', 'utf8').toString().replace(/{UNICODE}/g, '\u001b['))
this.logger.info('Starting switchblade...', { label: 'Switchblade' })
this.initializeLoaders()
this.connect()
}
initializeWinston() {
this.logger = winston.createLogger()
if (process.env.NODE_ENV === 'production') {
this.logger.add(new winston.transports.Console())
} else {
this.logger.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(
info => `${info.timestamp} ${info.level} [${info.label || ''}]: ${info.message}`
)
),
level: 'silly'
}))
}
}
async initializeLoaders() {
const loaders = [[], [], []]
for (let file in Loaders) {
const loader = new Loaders[file](this)
loaders[loader.priority].push(loader)
}
for (let loaderPriority of loaders) {
const priority = Object.keys(LoaderPriority)[loaders.indexOf(loaderPriority)]
this.logger.info(`Starting to load ${chalk.yellow(priority)}`, { label: 'Loaders' })
for (let loader of loaderPriority) {
let success = true
try {
success = await loader.preLoad()
} catch (error) {
this.logger.error(error.stack, { label: 'Loaders', stack: error.stack })
} finally {
if (!success && loader.critical) process.exit(1)
}
}
}
}
}