nodestatus-server 1.1.0-alpha.3 β 1.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.js +26 -6
- package/package.json +1 -1
package/build/app.js
CHANGED
|
@@ -60283,6 +60283,7 @@ const config = {
|
|
|
60283
60283
|
webPassword: process.env.WEB_PASSWORD || '',
|
|
60284
60284
|
webSecret: process.env.WEB_SECRET || process.env.WEB_PASSWORD || 'secret',
|
|
60285
60285
|
ipcAddress: process.env.IPC_ADDRESS || (require$$1$1.platform() !== 'win32' ? '/tmp/status_unix.sock' : '\\\\.\\pipe\\status_ipc'),
|
|
60286
|
+
pushTimeOut: Number(process.env.PUSH_TIMEOUT) || 30,
|
|
60286
60287
|
telegram: {
|
|
60287
60288
|
proxy: process.env.TGBOT_PROXY,
|
|
60288
60289
|
bot_token: process.env.TGBOT_TOKEN || '',
|
|
@@ -69035,10 +69036,7 @@ class NodeStatus {
|
|
|
69035
69036
|
this.isBanned.set(address, true);
|
|
69036
69037
|
logger.warn(`${address} was banned ${t} seconds, reason: ${reason}`);
|
|
69037
69038
|
callHook(this, 'onServerBanned', address, reason);
|
|
69038
|
-
|
|
69039
|
-
this.isBanned.delete(address);
|
|
69040
|
-
clearTimeout(id);
|
|
69041
|
-
}, t * 1000);
|
|
69039
|
+
setTimeout(() => this.isBanned.delete(address), t * 1000);
|
|
69042
69040
|
}
|
|
69043
69041
|
launch() {
|
|
69044
69042
|
this.server.on('upgrade', (request, socket, head) => {
|
|
@@ -69160,6 +69158,8 @@ class NodeStatus {
|
|
|
69160
69158
|
/* This should move to another file later */
|
|
69161
69159
|
createPush() {
|
|
69162
69160
|
const pushList = [];
|
|
69161
|
+
/* ip -> timer */
|
|
69162
|
+
const timerMap = new Map();
|
|
69163
69163
|
const entities = new Set(['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\']);
|
|
69164
69164
|
const parseEntities = (str) => {
|
|
69165
69165
|
if (typeof str !== 'string')
|
|
@@ -69245,8 +69245,27 @@ class NodeStatus {
|
|
|
69245
69245
|
}
|
|
69246
69246
|
pushList.push(message => [...chatId].map(id => bot.telegram.sendMessage(id, `${message}`, { parse_mode: 'MarkdownV2' })));
|
|
69247
69247
|
}
|
|
69248
|
-
this.onServerConnected = (socket, username) =>
|
|
69249
|
-
|
|
69248
|
+
this.onServerConnected = (socket, username) => {
|
|
69249
|
+
const ip = this.map.get(socket);
|
|
69250
|
+
if (ip) {
|
|
69251
|
+
const timer = timerMap.get(ip);
|
|
69252
|
+
if (timer) {
|
|
69253
|
+
clearTimeout(timer);
|
|
69254
|
+
timerMap.delete(ip);
|
|
69255
|
+
}
|
|
69256
|
+
else {
|
|
69257
|
+
return Promise.all(pushList.map(fn => fn(`π*NodeStatus* \nπ One new server has connected\\! \n\n *η¨ζ·ε*: ${parseEntities(username)} \n *θηΉε*: ${parseEntities(this.servers[username]['name'])} \n *ζΆι΄*: ${parseEntities(new Date())}`)));
|
|
69258
|
+
}
|
|
69259
|
+
}
|
|
69260
|
+
};
|
|
69261
|
+
this.onServerDisconnected = (socket, username) => {
|
|
69262
|
+
const ip = this.map.get(socket);
|
|
69263
|
+
const timer = setTimeout(() => {
|
|
69264
|
+
Promise.all(pushList.map(fn => fn(`π*NodeStatus* \nπ° One server has disconnected\\! \n\n *η¨ζ·ε*: ${parseEntities(username)} \n *θηΉε*: ${parseEntities(this.servers[username]?.['name'])} \n *ζΆι΄*: ${parseEntities(new Date())}`))).then();
|
|
69265
|
+
ip && timerMap.delete(ip);
|
|
69266
|
+
}, this.options.pushTimeOut * 1000);
|
|
69267
|
+
ip && timerMap.set(ip, timer);
|
|
69268
|
+
};
|
|
69250
69269
|
}
|
|
69251
69270
|
}
|
|
69252
69271
|
|
|
@@ -69256,6 +69275,7 @@ async function createStatus(app) {
|
|
|
69256
69275
|
const instance = new NodeStatus(server, {
|
|
69257
69276
|
interval: Number(config.interval),
|
|
69258
69277
|
usePush: config.usePush,
|
|
69278
|
+
pushTimeOut: config.pushTimeOut,
|
|
69259
69279
|
telegram: {
|
|
69260
69280
|
...config.telegram,
|
|
69261
69281
|
chat_id: config.telegram.chat_id.split(',')
|