-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
88 lines (75 loc) · 3.57 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
81
82
83
84
85
86
87
88
const { spawn } = require("child_process");
const { readFileSync } = require("fs-extra");
const http = require("http");
const axios = require("axios");
const semver = require("semver");
const logger = require("./utils/log");
/////////////////////////////////////////////
//========= Check node.js version =========https://
/////////////////////////////////////////////
// const nodeVersion = semver.parse(process.version);
// if (nodeVersion.major < 13) {
// logger(`Your Node.js ${process.version} is not supported, it required Node.js 13 to run bot!`, "error");
// return process.exit(0);
// };
///////////////////////////////////////////////////////////
//========= Create website for dashboard/uptime =========https://
///////////////////////////////////////////////////////////
const dashboard = http.createServer(function (_req, res) {
res.writeHead(200, "OK", { "Content-Type": "text/plain" });
res.write("HI! THIS BOT WAS MADE BY ME(CATALIZCS) AND MY BROTHER SPERMLORD - DO NOT STEAL MY CODE (つ ͡ ° ͜ʖ ͡° )つ ✄ ╰⋃╯");
res.end();
});
dashboard.listen(process.env.port || 0);
logger("Opened server site...", "[ Starting ]");
/////////////////////////////////////////////////////////
//========= Create start bot and make it loop =========https://
/////////////////////////////////////////////////////////
function startBot(message) {
(message) ? logger(message, "[ Starting ]") : "";
const child = spawn("node", ["--trace-warnings", "--async-stack-traces", "mirai.js"], {
cwd: __dirname,
stdio: "inherit",
shell: true
});
child.on("close", (codeExit) => {
if (codeExit != 0 || global.countRestart && global.countRestart < 5) {
startBot("Restarting...");
global.countRestart += 1;
return;
} else return;
});
child.on("error", function (error) {
logger("An error occurred: " + JSON.stringify(error), "[ Starting ]");
});
};
////////////////////////////////////////////////
//========= Check update from Github =========https://
////////////////////////////////////////////////
axios.get("https://raw.githubusercontent.com/d-jukie/miraiv2/main/package.json").then((res) => {
logger(res['data']['name'], "[ NAME ]");
logger("Version: " + res['data']['version'], "[ VERSION ]");
logger(res['data']['description'], "[ DESCRIPTION ]");
});
startBot();
/*axios.get("https://raw.githubusercontent.com/d-jukie/miraiv2_fix/main/package.json").then((res) => {
const local = JSON.parse(readFileSync('./package.json'));
if (semver['lt'](local.version, res['data']['version'])) {
if (local.autoUpdate == !![]) {
logger('A new update is available, start update processing...', '[ UPDATE ]');
const updateBot = {};
updateBot.cwd = __dirname
updateBot.stdio = 'inherit'
updateBot.shell = !![];
const child = spawn('node', ['update.js'], updateBot);
child.on('exit', function () {
return process.exit(0);
})
child.on('error', function (error) {
logger('Unable to update:' + JSON.stringify(error), '[ CHECK UPDATE ]');
});
} else logger('A new update is available! Open terminal/cmd and type "node update" to update!', '[ UPDATE ]'),
startBot();
} else logger('You are using the latest version!', '[ CHECK UPDATE ]'), startBot();
}).catch(err => logger("Unable to check update.", "[ CHECK UPDATE ]"));*/
// THIZ BOT WAS MADE BY ME(CATALIZCS) AND MY BROTHER SPERMLORD - DO NOT STEAL MY CODE (つ ͡ ° ͜ʖ ͡° )つ ✄ ╰⋃╯