add random delay (fix #1)

This commit is contained in:
Zichao Lin 2023-10-20 21:56:21 +08:00
parent 2ed58716bf
commit 5c8a9eb55e
Signed by: earthjasonlin
GPG Key ID: 406D9913DE2E42FB
4 changed files with 16 additions and 3 deletions

@ -1,4 +1,6 @@
{
"minDelay": 1000,
"maxDelay": 5000,
"sendMail": false,
"mailConfig": {
"user":"",

@ -1,7 +1,7 @@
const { exit } = require("process")
const fs = require("fs")
const { default: axios } = require("axios")
const { log } = require("./logger")
const { log } = require("./util")
exports.ListNotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?is_sort=true&source=NotificationSourceUnknown&status=NotificationStatusUnread&type=NotificationTypePopup'
exports.AckNotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/ackNotification'

@ -1,6 +1,6 @@
const { getConfigs, checkConfigs, makeHeader, ListNotification, AckNotification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
const { log, addLogContent, getLogs } = require("./logger");
const { log, addLogContent, getLogs, sleep } = require("./util");
const nodemailer = require("nodemailer");
@ -20,6 +20,8 @@ const nodemailer = require("nodemailer");
}
});
}
var minDelay = globalConfig.minDelay
var maxDelay = globalConfig.maxDelay
var configs = getConfigs();
log.info(`正在检测配置有效性`)
checkConfigs(configs)
@ -53,6 +55,9 @@ const nodemailer = require("nodemailer");
} else {
log.error("签到失败")
}
var delay = Math.round(Math.random() * (maxDelay - minDelay) + minDelay)
log.info(`暂停:${delay}毫秒`)
await sleep(delay);
}
if (globalConfig.sendMail == true) {

@ -17,4 +17,10 @@ exports.log = {
logContent += `<strong style="color: red">[error]</strong> ${content}<br>`
baseLogger.error(content)
}
}
}
exports.sleep = function (delay) {
return new Promise((resolve) => {
setTimeout(resolve, delay)
})
}