-
Notifications
You must be signed in to change notification settings - Fork 93
/
index.js
61 lines (53 loc) · 1.57 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
const fs = require("fs").promises;
const path = require("path");
const express = require("express");
const config = require("./config");
const { connect, writeSession, patch, parseDir, sleep } = require("./lib");
const { getandRequirePlugins } = require("./lib/db/plugins");
class BotSystem {
constructor() {
global.__basedir = __dirname;
this.app = express();
this.port = process.env.PORT || 3000;
}
async initialize() {
try {
await Promise.all([patch(), parseDir(path.join(__dirname, "/lib/db/")), parseDir(path.join(__dirname, "/plugins/")), this.ensureTempDir(), this.createGitignore()]);
await sleep(2000);
console.log("Syncing Database");
await config.DATABASE.sync();
await writeSession();
await getandRequirePlugins();
console.log("External Modules Installed");
return await connect();
} catch (error) {
console.error("Initialization error:", error);
}
}
startServer() {
this.app.get("/", (req, res) => res.send("Bot Running"));
}
async ensureTempDir() {
const dir = path.join(__dirname, "temp");
await fs.mkdir(dir, { recursive: true });
}
async createGitignore() {
const content = `node_modules
.gitignore
session
.env
package-lock.json
database.db
temp`;
await fs.writeFile(".gitignore", content);
}
async main() {
try {
await this.initialize();
this.startServer();
} catch (error) {
console.warn("BOT SYSTEM FAILED", error);
}
}
}
new BotSystem().main();