forked from vishwamihi/fxop-md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (71 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
const fs = require("fs").promises;
const path = require("path");
const express = require("express");
const config = require("./config");
const { connect, writeSession, patch, parseDir } = require("./lib");
const { getandRequirePlugins } = require("./lib/database/plugins");
class BotSystem {
constructor() {
global.__basedir = __dirname;
this.app = express();
this.port = process.env.PORT || 3000;
}
async initialize() {
try {
await patch();
await writeSession();
await parseDir(path.join(__dirname, "/lib/database/"));
console.log("Syncing Database");
await config.DATABASE.sync();
await parseDir(path.join(__dirname, "/plugins/"));
await getandRequirePlugins();
console.log("External Modules Installed");
return await connect();
} catch (error) {
console.error("Initialization error:", error);
}
}
async startServer() {
this.app.get("/", (req, res) => {
res.send("Bot Running");
});
this.app.listen(this.port, () => {});
}
async tempDir() {
const dir = path.join(__dirname, "temp");
try {
await fs.access(dir);
} catch (err) {
if (err.code === "ENOENT") {
await fs.mkdir(dir, { recursive: true });
}
}
}
async createGitignore() {
const content = `node_modules
.gitignore
session
.env
package-lock.json
database.db`;
fs.writeFile(".gitignore", content, err => {
if (err) {
console.error("Error creating .gitignore file:", err);
} else {
console.log(".gitignore file created successfully!");
}
});
}
async main() {
try {
await this.initialize();
await this.startServer();
await this.tempDir();
await this.createGitignore();
} catch (error) {
console.warn("BOT SYSTEM FAILED");
}
}
}
const botSystem = new BotSystem();
botSystem.main();