Working RSS Feeds
- Need to get worker in the background to update the sources
This commit is contained in:
28
libUtils.js
28
libUtils.js
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user