Files
Emmelia-Link-Flayer-Rewrite/controllers/rssController.js
2023-03-11 16:53:07 -05:00

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 30 seconds for the rest of the bot to start before starting rss feeds
await new Promise(resolve => setTimeout(resolve, 30000));
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;
}
}