From 1eb45bbe8c7d97c0fdd5100003a79c591addb6c3 Mon Sep 17 00:00:00 2001 From: adb Date: Wed, 31 Mar 2021 21:41:42 +0200 Subject: [PATCH] fix interval --- DynDnsBot.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/DynDnsBot.js b/DynDnsBot.js index 658a23f..5b62e80 100644 --- a/DynDnsBot.js +++ b/DynDnsBot.js @@ -18,14 +18,15 @@ export class DynDnsBot{ }); } setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){ - this.interval = setInterval(random - ?setTimeout(this.update, Math.random()*seconds*1000) - :this.update, - seconds*1000); + let handler = (callback) => random + ?()=>setTimeout(callback, Math.random()*seconds*1000) + :callback; + this.interval = setInterval(handler(this.update), seconds*1000); + this.update(); } async getIp(){ - return await rest.get(this.config.ipApi).then(newIp => { - return newIp; + return await rest.get(this.config.ipApi).then(res => { + return JSON.parse(res.text); }).catch(console.error); } } \ No newline at end of file