Files
drb-server/rss-manager/rssController.mjs
Logan Cusano 4e71c7b167 Initial RSS implementation
- Added debug command to trigger RSS feed update from discord
2024-05-22 00:17:36 -04:00

38 lines
1.3 KiB
JavaScript

//Will handle updating feeds in all channels
import { DebugBuilder } from "../modules/debugger.mjs";
import { updateFeeds } from "./feedHandler.mjs";
import dotenv from 'dotenv';
dotenv.config()
const log = new DebugBuilder("server", "rssController");
const refreshInterval = process.env.RSS_REFRESH_INTERVAL ?? 300000;
export 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 starting the infinite loop
await 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));
}
}
async collectLatestPosts() {
log.INFO("Updating sources");
await updateFeeds(this.client);
}
}