Updated RSS engine

- Added extended embedBuilder for Emmelia
- Improved RSS embed look
This commit is contained in:
Logan Cusano
2023-02-26 16:04:45 -05:00
parent 2b92b1dc1a
commit 96c10ade61
3 changed files with 30 additions and 19 deletions

View File

@@ -3,6 +3,13 @@ const { DebugBuilder } = require("./utilities/debugBuilder");
const log = new DebugBuilder("server", "libUtils");
const { NodeHtmlMarkdown } = require('node-html-markdown');
exports.EmmeliaEmbedBuilder = class PostEmbedBuilder extends EmbedBuilder {
constructor() {
super()
this.setFooter({ text: 'Brought to you by Emmelia.' });
}
}
/**
* sleep - sleep/wait
* @constructor
@@ -61,22 +68,27 @@ exports.onError = (error) => {
}
}
exports.sendPost = (post, channel, callback) => {
const title = post.title;
const link = post.link;
const content = NodeHtmlMarkdown.translate(post.content);
exports.sendPost = (post, source, channel, callback) => {
const postTitle = post.title;
const postLink = post.link;
const postContent = NodeHtmlMarkdown.translate(post.content);
const postId = post.postId;
const pubDate = new Date(post.pubDate).toISOString() ?? new Date().toISOString();
log.DEBUG("Sending an RSS post to discord", title, postId)
const postPubDate = new Date(post.pubDate).toISOString() ?? new Date().toISOString();
var postSourceLink = new URL(source.link);
postSourceLink = postSourceLink.hostname;
const postImage = post.image ?? undefined;
log.DEBUG("Sending an RSS post to discord", postTitle, postId)
const rssMessage = new EmbedBuilder()
const rssMessage = new this.EmmeliaEmbedBuilder()
.setColor(0x0099FF)
.setTitle(title)
.setURL(link)
.setDescription(`${content}`)
.addFields({ name: 'Published', value: pubDate, inline: true })
.setTimestamp()
.setFooter({ text: 'Brought to you by Emmelia.' });
.setTitle(postTitle)
.setURL(postLink)
.addFields({ name: "Post Content", value: postContent, inline: false })
.addFields({ name: 'Published', value: postPubDate, inline: true })
.addFields({ name: 'Source', value: postSourceLink, inline: true })
.setTimestamp()
if (postImage) rssMessage.setImage(postImage);
try{
channel.send({ embeds: [rssMessage] });