add random delay (fix #1)
This commit is contained in:
		@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -18,3 +18,9 @@ exports.log = {
 | 
			
		||||
        baseLogger.error(content)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.sleep = function (delay) {
 | 
			
		||||
    return new Promise((resolve) => {
 | 
			
		||||
      setTimeout(resolve, delay)
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
		Reference in New Issue
	
	Block a user