39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
//Will handle updating feeds in all channels
|
|
|
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
|
const log = new DebugBuilder("server", "rssController");
|
|
|
|
const libCore = require("../libCore");
|
|
const libUtils = require("../libUtils");
|
|
|
|
const refreshInterval = process.env.RSS_REFRESH_INTERVAL ?? 300000;
|
|
|
|
exports.RSSController = class RSSController {
|
|
constructor(_client) {
|
|
this.client = _client;
|
|
}
|
|
|
|
async start(){
|
|
// Wait for the refresh period before starting rss feeds, so the rest of the bot can start
|
|
await new Promise(resolve => setTimeout(resolve, refreshInterval));
|
|
|
|
log.INFO("Starting RSS Controller");
|
|
// Get initial feeds before the starting the infinite loop
|
|
await libCore.updateFeeds(this.client);
|
|
|
|
while(true){
|
|
// Wait for the refresh interval, then wait for the posts to return, then wait a quarter of the refresh interval to make sure everything is cleared up
|
|
await new Promise(resolve => setTimeout(resolve, refreshInterval));
|
|
await this.collectLatestPosts();
|
|
await new Promise(resolve => setTimeout(resolve, refreshInterval / 4));
|
|
continue;
|
|
}
|
|
}
|
|
|
|
async collectLatestPosts(){
|
|
log.INFO("Updating sources");
|
|
await libCore.updateFeeds(this.client)
|
|
return;
|
|
}
|
|
}
|