forked from ntkhang03/Goat-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.js
More file actions
48 lines (43 loc) · 1.95 KB
/
update.js
File metadata and controls
48 lines (43 loc) · 1.95 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
(async function () {
const fs = require("fs-extra");
const axios = require("axios");
const print = require("./logger/print.js");
const chalk = require("chalk");
const allVersion = (await axios.get("https://github.com/ntkhang03/Goat-Bot/raw/main/versions.json")).data;
const localVersion = require("./package.json").version;
if (allVersion[allVersion.length - 1].version == localVersion)
return print("Bạn đang sử dụng phiên bản mới nhất rồi", "LATEST VERSION");
fs.writeFileSync(__dirname + "/versions.json", JSON.stringify(allVersion, null, 2));
const indexCurrentVersion = allVersion.findIndex(item => item.version == localVersion);
const versionsUpdate = allVersion.slice(indexCurrentVersion + 1);
for (const data of versionsUpdate) {
if (data.del) {
for (const path in data.del)
try {
fs.unlinkSync(path);
}
catch (e) {
}
}
const { info, version } = data;
print.green(version, "VERSION");
for (const location in info) {
let response = (await axios.get(`https://github.com/ntkhang03/Goat-Bot/raw/main/${location}`, {
responseType: "arraybuffer"
})).data.toString();
let description = data.info[location];
if (location == "config.json" && description.keysNeddUpdate) {
const getNewConfig = JSON.parse(response);
const oldConfig = require("./config.json");
description = description.description;
const keysNeddUpdate = description.keysNeddUpdate;
for (const key of keysNeddUpdate) oldConfig[key] = getNewConfig[key];
response = JSON.stringify(oldConfig, null, 2);
}
fs.writeFileSync(`${__dirname}/${location}`, response);
print.green(`Update file ${chalk.hex("#ff5208")(location)} success, description: ${chalk.hex("#d6d6d6")(description || "No description")}`, "UPDATE");
}
}
const packageJson = (await axios.get("https://github.com/ntkhang03/Goat-Bot/raw/main/package.json")).data;
fs.writeFileSync(__dirname + "/package.json", JSON.stringify(packageJson, null, 2));
})();