-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathindex.js
executable file
·67 lines (60 loc) · 1.86 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
/* Copyright (C) 2025 Codex.
Licensed under the MIT License;
you may not use this file except in compliance with the License.
Codex - Ziyan
*/
const fs = require("fs").promises;
const fsx = require("fs");
const path = require("path");
const config = require("./config");
const connect = require("./lib/connection");
const { getandRequirePlugins } = require("./lib/db/plugins");
const { UpdateLocal, WriteSession, overrideConsoleLogs } = require("./lib");
global.__basedir = __dirname;
process.on('message', (data) => {
if (data.type === 'overrideLogs') {
// Override console methods in the worker process
overrideConsoleLogs();
}
});
async function auth() {
try {
if (!fsx.existsSync("./lib/session/creds.json")) {
await WriteSession();
}
return initialize();
} catch (error) {
console.error("AuthFile Generation Error:", error);
return process.exit(1);
}
}
const readAndRequireFiles = async (directory) => {
try {
const files = await fs.readdir(directory);
return Promise.all(
files
.filter((file) => path.extname(file).toLowerCase() === ".js")
.map((file) => require(path.join(directory, file)))
);
} catch (error) {
console.error("Error reading and requiring files:", error);
throw error;
}
};
async function initialize() {
console.log("============> WhatsBixby [Codex] <============");
try {
await readAndRequireFiles(path.join(__dirname, "/lib/db/"));
console.log("Syncing Database");
await config.DATABASE.sync();
console.log("⬇ Installing Plugins...");
await readAndRequireFiles(path.join(__dirname, "/plugins/"));
await getandRequirePlugins();
console.log("✅ Plugins Installed!");
return await connect();
} catch (error) {
console.error("Initialization error:", error);
return process.exit(1); // Exit with error status
}
}
auth();