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

@@ -2,7 +2,7 @@ const { submitPromptTransaction } = require("../controllers/chatGptController");
const { SlashCommandBuilder } = require('discord.js'); const { SlashCommandBuilder } = require('discord.js');
const { DebugBuilder } = require("../utilities/debugBuilder"); const { DebugBuilder } = require("../utilities/debugBuilder");
const log = new DebugBuilder("server", "chat"); const log = new DebugBuilder("server", "chat");
const { EmbedBuilder } = require('discord.js'); const { EmmeliaEmbedBuilder } = require('../libUtils');
module.exports = { module.exports = {
@@ -39,7 +39,7 @@ module.exports = {
submitPromptTransaction(promptText, temperature, maxTokens, discordAccountId, async (err, result) => { submitPromptTransaction(promptText, temperature, maxTokens, discordAccountId, async (err, result) => {
if (err) throw err; if (err) throw err;
const gptEmbed = new EmbedBuilder() const gptEmbed = new EmmeliaEmbedBuilder()
.setColor(0x0099FF) .setColor(0x0099FF)
.setTitle(`New GPT response`) .setTitle(`New GPT response`)
.setDescription(`${interaction.member.user} sent: '${promptText}'`) .setDescription(`${interaction.member.user} sent: '${promptText}'`)
@@ -47,8 +47,7 @@ module.exports = {
{ name: 'Generated Text', value: result.promptResult }, { name: 'Generated Text', value: result.promptResult },
) )
.addFields({ name: 'Tokens Used', value: `${result.totalTokens}`, inline: true }) .addFields({ name: 'Tokens Used', value: `${result.totalTokens}`, inline: true })
.setTimestamp() .setTimestamp()
.setFooter({ text: 'Brought to you by Emmelia.' });
await interaction.editReply({ embeds: [gptEmbed], ephemeral: false }); await interaction.editReply({ embeds: [gptEmbed], ephemeral: false });
}); });

View File

@@ -95,7 +95,7 @@ exports.updateFeeds = async (client) => {
if (parsedFeed?.items){ if (parsedFeed?.items){
for (const post of parsedFeed.items){ for (const post of parsedFeed.items){
log.VERBOSE("Post from feed: ", post); //log.VERBOSE("Post from feed: ", post);
if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){ if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){
post.postId = post.postId ?? post.guid ?? post.id; post.postId = post.postId ?? post.guid ?? post.id;
postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => { postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => {
@@ -103,7 +103,7 @@ exports.updateFeeds = async (client) => {
log.DEBUG("Existing post record: ", existingRecord); log.DEBUG("Existing post record: ", existingRecord);
if (!existingRecord){ if (!existingRecord){
const channel = client.channels.cache.get(source.channel_id); const channel = client.channels.cache.get(source.channel_id);
libUtils.sendPost(post, channel, (err, sendResults) =>{ libUtils.sendPost(post, source, channel, (err, sendResults) =>{
if (err) throw err; if (err) throw err;
if (sendResults){ if (sendResults){

View File

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