|
|
@ -8,7 +8,7 @@ export class DynDnsBot{
|
|
|
|
this.lastIp = null;
|
|
|
|
this.lastIp = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async update() {
|
|
|
|
async update(){
|
|
|
|
let newIp = await this.getIp();
|
|
|
|
let newIp = await this.getIp();
|
|
|
|
if (newIp === this.lastIp) return;
|
|
|
|
if (newIp === this.lastIp) return;
|
|
|
|
this.lastIp = newIp;
|
|
|
|
this.lastIp = newIp;
|
|
|
@ -18,15 +18,15 @@ export class DynDnsBot{
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){
|
|
|
|
setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){
|
|
|
|
let handler = (callback) => random
|
|
|
|
let handler = random
|
|
|
|
?()=>setTimeout(callback, Math.random()*seconds*1000)
|
|
|
|
? (callback) => setTimeout(callback, Math.random()*seconds*1000)
|
|
|
|
:callback;
|
|
|
|
: (callback) => callback();
|
|
|
|
this.interval = setInterval(handler(this.update), seconds*1000);
|
|
|
|
this.interval = setInterval(handler(()=>this.update()), seconds*1000);
|
|
|
|
this.update();
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async getIp(){
|
|
|
|
async getIp(){
|
|
|
|
return await rest.get(this.config.ipApi).then(res => {
|
|
|
|
return await rest.get(this.config.ipApi).then(res => {
|
|
|
|
return JSON.parse(res.text);
|
|
|
|
return res.text;
|
|
|
|
}).catch(console.error);
|
|
|
|
}).catch(console.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|