//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); } }