Working RSS Feeds

- Need to get worker in the background to update the sources
This commit is contained in:
Logan Cusano
2023-02-25 19:51:49 -05:00
parent ae071be8b8
commit d33f1ceccc
9 changed files with 218 additions and 250 deletions

View File

@@ -1,5 +1,7 @@
const { EmbedBuilder } = require('discord.js');
const { DebugBuilder } = require("./utilities/debugBuilder");
const log = new DebugBuilder("server", "libUtils");
const { NodeHtmlMarkdown } = require('node-html-markdown');
/**
* sleep - sleep/wait
@@ -57,4 +59,30 @@ exports.onError = (error) => {
default:
throw error;
}
}
exports.sendPost = (post, channel, callback) => {
const title = post.title;
const link = post.link;
const content = NodeHtmlMarkdown.translate(post.content);
const guid = post.guid;
const pubDate = post.pubDate ?? new Date();
log.DEBUG("Sending an RSS post to discord", title, guid)
const rssMessage = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(title)
.setURL(link)
.setDescription(content)
.setTimestamp(pubDate)
.setFooter({ text: 'Brought to you by Emmelia.' });
try{
channel.send({ embeds: [rssMessage] });
return callback(undefined, true);
}
catch (err){
log.ERROR("Error sending message: ", err);
return callback(err, undefined);
}
}