-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathindex.js
29 lines (26 loc) · 804 Bytes
/
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
const path = require("path");
const config = require("./config");
const bot = require("./lib/bot");
const fs = require("fs").promises;
const fetchSession = require("./lib/session");
global.__basedir = __dirname;
async function startBot() {
console.log("🤖 Initializing..");
try {
console.log("Syncing Database 💾");
await config.DATABASE.sync();
const sessionPath = path.join(__dirname, "session");
try {
await fs.rm(sessionPath, { recursive: true, force: true });
} catch (err) {
if (err.code !== "ENOENT") throw err;
}
await fs.mkdir(sessionPath);
await fetchSession(config.SESSION_ID);
return await bot();
} catch (error) {
console.error("Initialization error:", error);
process.exit(1); // Exit with error status
}
}
startBot();