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
71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
|
|
import { SlashCommandBuilder } from 'discord.js';
|
|
import { DebugBuilder } from "../../modules/debugger.mjs";
|
|
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('rss-add')
|
|
.setDescription('Add RSS Source')
|
|
.addStringOption(option =>
|
|
option.setName('title')
|
|
.setDescription('The title of the RSS feed')
|
|
.setRequired(true))
|
|
.addStringOption(option =>
|
|
option.setName('link')
|
|
.setDescription('The link to the RSS feed')
|
|
.setRequired(true))
|
|
.addStringOption(option =>
|
|
option.setName('category')
|
|
.setDescription('The category for the RSS feed *("ALL" by default")*')
|
|
.setRequired(false))
|
|
|
|
// Exporting other properties
|
|
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.
|
|
|
|
/**
|
|
* Function to give the user auto-reply suggestions
|
|
* @param {any} nodeIo The nodeIO server for manipulation of sockets
|
|
* @param {any} interaction The interaction object
|
|
*/
|
|
|
|
// TODO - Setup autocorrect for the category
|
|
/*
|
|
export async function autocomplete(nodeIo, interaction) {
|
|
const focusedValue = interaction.options.getFocused();
|
|
const choices = [];
|
|
const filtered = choices.filter(choice => choice.name.startsWith(focusedValue));
|
|
log.DEBUG(focusedValue, choices, filtered);
|
|
await interaction.respond(filtered);
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* 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');
|
|
var link = interaction.options.getString('link');
|
|
var category = interaction.options.getString('category');
|
|
|
|
if (!category) category = "ALL";
|
|
|
|
await addSource(title, link, category, interaction.guildId, interaction.channelId, (err, result) => {
|
|
log.DEBUG("Result from adding entry", result);
|
|
|
|
if (result) {
|
|
interaction.reply(`Successfully added ${title} to the list of RSS sources`);
|
|
} else {
|
|
interaction.reply(`${title} already exists in the list of RSS sources`);
|
|
}
|
|
});
|
|
} catch (err) {
|
|
log.ERROR(err)
|
|
await interaction.reply(err.toString());
|
|
}
|
|
} |