-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (34 loc) · 813 Bytes
/
Copy pathindex.js
File metadata and controls
44 lines (34 loc) · 813 Bytes
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
const rl = require("serverline");
const Bot = require("./bot");
const config = require("./config");
const logger = require("./logger");
process.stdin.setEncoding("utf8");
process.stderr.setEncoding("utf8");
const bot = new Bot(config.bot.token);
rl.init();
rl.setCompletion(["stop", "reload"]);
rl.setPrompt("> ");
rl.on("line", async line => {
const command = line.trim();
switch (command) {
case "stop":
await bot.stop();
break;
case "reload":
await bot.reload();
break;
}
});
rl.on("SIGINT", rl => {
rl.question("Confirm exit: ", answer =>
answer.match(/^y(es)?$/i)
? bot.stop()
: rl.output.write("\x1b[1K> "));
});
process.on("SIGINT", bot.stop);
process.on("SIGTERM", bot.stop);
process.on("uncaughtException", e => {
logger.error(e);
bot.reload();
});
bot.start();