4chan-full
Version:
www.4chan.org non-official read only api. That supports cool things!
120 lines (98 loc) • 3.27 kB
JavaScript
const { FourChanFull } = require("../FourChanFull");
const { EventEmitter } = require("events");
const sleep = require("stuffs/lib/sleep");
const { Thread } = require("../types/Thread");
const { resolve } = require("path");
class ThreadWatcher {
/** @type {FourChanFull} */
fchf;
boardCode: "",
threadId: "",
checkIntervalMin: 0,
checkIntervalMax: 0,
checkIntervalAdder: 0
}
get options() {
return this.
}
get checkInterval() {
return this.
}
get running() {
return this.
}
/** @type {Thread} */
get lastResult() {
return this.
}
get startTime() {
return this.
}
events = new EventEmitter();
on(eventName, listener) {
this.events.on(eventName, listener);
}
off(eventName, listener) {
this.events.off(eventName, listener);
}
/**
* @param {FourChanFull} fchf
* @param {{boardCode:string,threadId:string,checkIntervalMin:number,checkIntervalMax:number,checkIntervalAdder:number}} options
*/
constructor(fchf, options) {
this.fchf = fchf;
this.
this.
this.
this.
this.
}
start() {
const self = this;
const { boardCode, threadId, checkIntervalAdder, checkIntervalMax, checkIntervalMin, onUpdate } = this.options;
return new Promise(async (resolve, reject) => {
if (self.
self.
self.
self.
self.events.emit("#start");
async function _check() {
if (!self.
try {
let thread = await self.fchf.thread(boardCode, threadId);
resolve();
if (self.
self.
self.events.emit("updated", self.
} else {
self.
if (self.
self.events.emit("notUpdated");
}
self.events.emit("checked", self.
self.
await sleep(self.
_check();
} catch (err) {
self.
self.events.emit("error", err);
reject(err);
}
}
_check();
})
}
stop() {
return new Promise(async (resolve, reject) => {
this.
this.
this.events.once("#stop", resolve);
})
}
}
module.exports = { ThreadWatcher };