-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreload.js
42 lines (35 loc) · 1.19 KB
/
reload.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
const fs = require('fs');
const Command = require('../command.js')
const CommandHandler = require('../_commandHandler.js')
const ObserverHandler = require('../../observers/_observerHandler.js')
/*
* A module for reloading (other) modules. This will purge a named module
* from the require cache and reload it from disk, effectively hotswapping
* the updated code (or resetting state, if something gets really fucked up).
*/
module.exports = class Reload extends Command {
constructor() {
super('reload')
}
async call(bot, opts, respond) {
if (!this.adminCallable(opts)) return
const moduleName = opts.args[0];
let numReloaded = 0;
try {
if (await CommandHandler.reload(moduleName)) {
numReloaded++
}
if (await ObserverHandler.reload(moduleName)) {
numReloaded++
}
if (numReloaded > 0) {
return respond("Reloaded " + moduleName + " (" + numReloaded + " total)")
} else {
return respond(`No observer or command modules named "${moduleName}" found`)
}
} catch (e) {
console.error(e)
return respond(`Error reloading module "${moduleName}": ${e.message}. Check logs for more info`)
}
}
}