From 581fadba8f55b88465afc319db6ec7e3871a56ef Mon Sep 17 00:00:00 2001 From: adb Date: Thu, 1 Apr 2021 23:23:04 +0200 Subject: [PATCH] fix DynDnsBot timout --- DynDnsBot.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DynDnsBot.js b/DynDnsBot.js index 5b62e80..629e7ec 100644 --- a/DynDnsBot.js +++ b/DynDnsBot.js @@ -8,7 +8,7 @@ export class DynDnsBot{ this.lastIp = null; } - async update() { + async update(){ let newIp = await this.getIp(); if (newIp === this.lastIp) return; this.lastIp = newIp; @@ -18,15 +18,15 @@ export class DynDnsBot{ }); } setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){ - let handler = (callback) => random - ?()=>setTimeout(callback, Math.random()*seconds*1000) - :callback; - this.interval = setInterval(handler(this.update), seconds*1000); + let handler = random + ? (callback) => setTimeout(callback, Math.random()*seconds*1000) + : (callback) => callback(); + this.interval = setInterval(handler(()=>this.update()), seconds*1000); this.update(); } async getIp(){ return await rest.get(this.config.ipApi).then(res => { - return JSON.parse(res.text); + return res.text; }).catch(console.error); } } \ No newline at end of file