Initial RSS implementation
- Added debug command to trigger RSS feed update from discord
This commit is contained in:
37
rss-manager/rssController.mjs
Normal file
37
rss-manager/rssController.mjs
Normal file
@@ -0,0 +1,37 @@
|
||||
//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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user