Linting
All checks were successful
release-tag / release-image (push) Successful in 1m52s
Lint JavaScript/Node.js / lint-js (push) Successful in 11s
DRB Tests / drb_mocha_tests (push) Successful in 29s

This commit is contained in:
Logan Cusano
2024-08-11 15:57:46 -04:00
parent 5cd47378d6
commit 117cbea67f
37 changed files with 2273 additions and 1738 deletions

View File

@@ -1,19 +1,23 @@
import { SlashCommandBuilder } from 'discord.js';
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'
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')
.setName("rss-remove")
.setDescription("Add RSS Source")
.addStringOption((option) =>
option
.setName("title")
.setDescription("The title of the RSS feed")
.setRequired(true)
.setAutocomplete(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
@@ -27,11 +31,15 @@ export const deferInitialReply = false; // If we the initial reply in discord sh
export async function autocomplete(nodeIo, interaction) {
const focusedValue = interaction.options.getFocused();
const choices = await getAllFeeds() ?? [];
const choices = (await getAllFeeds()) ?? [];
log.INFO("RSS Remove Choices:", choices);
const filtered = choices.filter(choice => choice.title.startsWith(focusedValue));
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 })));
await interaction.respond(
filtered.map((choice) => ({ name: choice.title, value: choice.title })),
);
}
/**
@@ -41,8 +49,10 @@ export async function autocomplete(nodeIo, interaction) {
*/
export const execute = async (nodeIo, interaction) => {
try {
var title = interaction.options.getString('title');
await interaction.reply(`Removing ${title} from the list of RSS sources, please wait...`);
var title = interaction.options.getString("title");
await interaction.reply(
`Removing ${title} from the list of RSS sources, please wait...`,
);
const results = await deleteFeedByTitle(title);
if (!results) {
@@ -50,9 +60,11 @@ export const execute = async (nodeIo, interaction) => {
await interaction.editReply(`Failed to remove source: '${title}'`);
return;
}
await interaction.editReply(`${title} was successfully removed from the RSS sources.`)
await interaction.editReply(
`${title} was successfully removed from the RSS sources.`,
);
} catch (err) {
log.ERROR(err)
log.ERROR(err);
await interaction.editReply(err.toString());
}
}
};