RSS improvements
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 31s
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 31s
- Updated rss discord command name scheme - Implemented new sourceManager for handling feed sources - Added wrappers to delete/get feed sources by title
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
import { addSource } from '../../rss-manager/feedHandler.mjs'
|
||||
const log = new DebugBuilder("server", "discordBot.command.add");
|
||||
import { addSource } from '../../rss-manager/sourceManager.mjs'
|
||||
const log = new DebugBuilder("server", "discordBot.command.rssAdd");
|
||||
|
||||
// Exporting data property that contains the command structure for discord including any params
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('add')
|
||||
.setName('rss-add')
|
||||
.setDescription('Add RSS Source')
|
||||
.addStringOption(option =>
|
||||
option.setName('title')
|
||||
@@ -22,7 +22,7 @@ export const data = new SlashCommandBuilder()
|
||||
.setRequired(false))
|
||||
|
||||
// Exporting other properties
|
||||
export const example = "/add [title] [https://domain.com/feed.xml] [category]"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||
export const example = "/rss-add [title] [https://domain.com/feed.xml] [category]"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||
export const deferInitialReply = false; // If we the initial reply in discord should be deferred. This gives extra time to respond, however the method of replying is different.
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ export const execute = async (nodeIo, interaction) => {
|
||||
log.DEBUG("Result from adding entry", result);
|
||||
|
||||
if (result) {
|
||||
interaction.reply(`Adding ${title} to the list of RSS sources`);
|
||||
interaction.reply(`Successfully added ${title} to the list of RSS sources`);
|
||||
} else {
|
||||
interaction.reply(`${title} already exists in the list of RSS sources`);
|
||||
}
|
||||
58
discordBot/commands/rssRemove.mjs
Normal file
58
discordBot/commands/rssRemove.mjs
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
import { removeSource } from '../../rss-manager/sourceManager.mjs'
|
||||
import { getAllFeeds, deleteFeedByTitle } from '../../modules/mongo-wrappers/mongoFeedsWrappers.mjs'
|
||||
const log = new DebugBuilder("server", "discordBot.command.rssRemove");
|
||||
|
||||
// Exporting data property that contains the command structure for discord including any params
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('rss-remove')
|
||||
.setDescription('Add RSS Source')
|
||||
.addStringOption(option =>
|
||||
option.setName('title')
|
||||
.setDescription('The title of the RSS feed')
|
||||
.setRequired(true)
|
||||
.setAutocomplete(true))
|
||||
|
||||
// Exporting other properties
|
||||
export const example = "/rss-remove [title]"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||
export const deferInitialReply = false; // If we the initial reply in discord should be deferred. This gives extra time to respond, however the method of replying is different.
|
||||
|
||||
/**
|
||||
* Function to give the user auto-reply suggestions
|
||||
* @param {any} nodeIo The nodeIO server for manipulation of sockets
|
||||
* @param {any} interaction The interaction object
|
||||
*/
|
||||
|
||||
export async function autocomplete(nodeIo, interaction) {
|
||||
const focusedValue = interaction.options.getFocused();
|
||||
const choices = await getAllFeeds() ?? [];
|
||||
log.INFO("RSS Remove Choices:", choices);
|
||||
const filtered = choices.filter(choice => choice.title.startsWith(focusedValue));
|
||||
log.DEBUG(focusedValue, choices, filtered);
|
||||
await interaction.respond(filtered.map(choice => ({ name: choice.title, value: choice.title })));
|
||||
}
|
||||
|
||||
/**
|
||||
* The function to run when the command is called by a discord user
|
||||
* @param {any} nodeIo The nodeIO server for manipulation of sockets
|
||||
* @param {any} interaction The interaction object
|
||||
*/
|
||||
export const execute = async (nodeIo, interaction) => {
|
||||
try {
|
||||
var title = interaction.options.getString('title');
|
||||
interaction.reply(`Removing ${title} from the list of RSS sources, please wait...`);
|
||||
|
||||
const results = await deleteFeedByTitle(title);
|
||||
if (!results) {
|
||||
log.WARN(`Failed to remove source: ${title}`);
|
||||
interaction.editReply(`Failed to remove source: '${title}'`);
|
||||
return;
|
||||
}
|
||||
interaction.editReply(`${title} was successfully removed from the RSS sources.`)
|
||||
} catch (err) {
|
||||
log.ERROR(err)
|
||||
interaction.editReply(err.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "discordBot.command.triggerRss");
|
||||
const log = new DebugBuilder("server", "discordBot.command.rssTrigger");
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { updateFeeds } from '../../rss-manager/feedHandler.mjs'
|
||||
|
||||
// Exporting data property that contains the command structure for discord including any params
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('trigger-rss')
|
||||
.setName('rss-trigger')
|
||||
.setDescription('Manually triggers an RSS feed update');
|
||||
|
||||
// Exporting other properties
|
||||
export const example = "/trigger-rss"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||
export const example = "/rss-trigger"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||
export const deferInitialReply = false; // If we the initial reply in discord should be deferred. This gives extra time to respond, however the method of replying is different.
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ const log = new DebugBuilder("server", "discordBot.modules.rssWrappers");
|
||||
const imageRegex = /(http(s?):)([/|.|\w|\s|-])*((\.(?:jpg|gif|png|webm))|(\/gallery\/(?:[/|.|\w|\s|-])*))/g;
|
||||
const youtubeVideoRegex = /((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)/g;
|
||||
|
||||
export class EmmeliaEmbedBuilder extends EmbedBuilder {
|
||||
export class DRBEmbedBuilder extends EmbedBuilder {
|
||||
constructor() {
|
||||
super();
|
||||
this.setTimestamp();
|
||||
@@ -66,7 +66,7 @@ export const sendPost = (post, source, channel) => {
|
||||
log.DEBUG("Post content: ", postContent);
|
||||
|
||||
try {
|
||||
const rssMessage = new EmmeliaEmbedBuilder()
|
||||
const rssMessage = new DRBEmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle(postTitle)
|
||||
.setURL(postLink)
|
||||
|
||||
Reference in New Issue
Block a user