-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathindex.js
More file actions
153 lines (125 loc) · 4.13 KB
/
index.js
File metadata and controls
153 lines (125 loc) · 4.13 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const { exec } = require("child_process");
const chalk = require("chalk");
const check = require("get-latest-version");
const fs = require("fs");
const semver = require("semver");
global.loading = require("./utils/log.js");
let configJson;
let packageJson;
const sign = "(›^-^)›";
const fbstate = "appstate.json";
try {
configJson = require("./config.json");
} catch (error) {
console.error("Error loading config.json:", error);
process.exit(1); // Exit the script with an error code
}
const delayedLog = async (message) => {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const char of message) {
process.stdout.write(char);
await delay(50);
}
console.log();
};
const showMessage = async () => {
const message =
chalk.yellow(" ") +
`The "removeSt" property is set true in the config.json. Therefore, the Appstate was cleared effortlessly! You can now place a new one in the same directory.`;
await delayedLog(message);
};
if (configJson.removeSt) {
fs.writeFileSync(fbstate, sign, { encoding: "utf8", flag: "w" });
showMessage();
configJson.removeSt = false;
fs.writeFileSync(
"./config.json",
JSON.stringify(configJson, null, 2),
"utf8",
);
setTimeout(() => {
process.exit(0);
}, 10000);
return;
}
// # Please note that sometimes this function is the reason the bot will auto-restart, even if your custom.js auto-restart is set to false. This is because the port switches automatically if it is unable to connect to the current port. ↓↓↓↓↓↓
const excluded = configJson.UPDATE.EXCLUDED || [];
try {
packageJson = require("./package.json");
} catch (error) {
console.error("Error loading package.json:", error);
return;
}
function nv(version) {
return version.replace(/^\^/, "");
}
async function updatePackage(dependency, currentVersion, latestVersion) {
if (!excluded.includes(dependency)) {
const ncv = nv(currentVersion);
if (semver.neq(ncv, latestVersion)) {
console.log(
chalk.bgYellow.bold(` UPDATE `),
`There is a newer version ${chalk.yellow(`(^${latestVersion})`)} available for ${chalk.yellow(dependency)}. Updating to the latest version...`,
);
packageJson.dependencies[dependency] = `^${latestVersion}`;
fs.writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
console.log(
chalk.green.bold(`UPDATED`),
`${chalk.yellow(dependency)} updated to ${chalk.yellow(`^${latestVersion}`)}`,
);
exec(`npm install ${dependency}@latest`, (error, stdout, stderr) => {
if (error) {
console.error("Error executing npm install command:", error);
return;
}
console.log("npm install output:", stdout);
});
}
}
}
async function checkAndUpdate() {
if (configJson.UPDATE && configJson.UPDATE.Package) {
try {
for (const [dependency, currentVersion] of Object.entries(
packageJson.dependencies,
)) {
const latestVersion = await check(dependency);
await updatePackage(dependency, currentVersion, latestVersion);
}
} catch (error) {
console.error("Error checking and updating dependencies:", error);
}
} else {
console.log(
chalk.yellow(""),
"Update for packages is not enabled in config.json",
);
}
}
// Do not remove anything if you don't know what you're doing! -Yan
setTimeout(() => {
checkAndUpdate();
}, 20000);
const path = require("path");
const express = require("express");
const parser = require("body-parser");
const app = express();
app.use(parser.json());
// Serve all static files from the whole project
app.use(express.static(path.join(__dirname, "includes/cover")));
// Route to serve config.json
app.get("/themes", (req, res) => {
res.sendFile(path.join(__dirname, "includes/cover/html.json"));
});
// Serve index.html from includes/cover
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "includes/cover/index.html"));
});
app.listen(2024, () => {
global.loading.log(
`Bot is running on port: 2024`,
"SYSTEM",
);
});
// __@YanMaglinte was Here__ //
// ----------------------------//