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,28 @@
import { DebugBuilder } from "../../modules/debugger.mjs";
import { SlashCommandBuilder } from 'discord.js';
import { joinNode, getAvailableNodes, promptNodeSelection, getUserVoiceChannel } from '../modules/wrappers.mjs';
import { getAllSystems, getSystemByName } from '../../modules/mongo-wrappers/mongoSystemsWrappers.mjs';
import { SlashCommandBuilder } from "discord.js";
import {
joinNode,
getAvailableNodes,
promptNodeSelection,
getUserVoiceChannel,
} from "../modules/wrappers.mjs";
import {
getAllSystems,
getSystemByName,
} from "../../modules/mongo-wrappers/mongoSystemsWrappers.mjs";
const log = new DebugBuilder("server", "discordBot.command.join");
// Exporting data property
export const data = new SlashCommandBuilder()
.setName('join')
.setDescription('Listen to the selected radio system in your channel')
.addStringOption(system =>
system.setName('system')
.setDescription('The radio system you would like to listen to')
.setName("join")
.setDescription("Listen to the selected radio system in your channel")
.addStringOption((system) =>
system
.setName("system")
.setDescription("The radio system you would like to listen to")
.setRequired(true)
.setAutocomplete(true)
.setAutocomplete(true),
);
// Exporting other properties
@@ -28,16 +37,17 @@ export const deferInitialReply = true;
export async function autocomplete(nodeIo, interaction) {
const focusedValue = interaction.options.getFocused();
const choices = await getAllSystems();
const filtered = choices.filter(choice => choice.name.startsWith(focusedValue));
const filtered = choices.filter((choice) =>
choice.name.startsWith(focusedValue),
);
log.DEBUG(focusedValue, choices, filtered);
try {
await interaction.respond(
filtered.map(choice => ({ name: choice.name, value: choice.name }))
filtered.map((choice) => ({ name: choice.name, value: choice.name })),
);
}
catch (e) {
} catch (e) {
log.WARN("Autocomplete interaction failure", e);
}
}
@@ -54,40 +64,66 @@ export async function execute(nodeIo, interaction) {
if (!channelToJoin) return;
// Get the selected system
const selectedSystemName = interaction.options.getString('system');
const selectedSystemName = interaction.options.getString("system");
const system = await getSystemByName(selectedSystemName);
// Check if there was a system found by the given system name
if (!system) {
await interaction.editReply({ content: `System '${selectedSystemName}' not found.`, ephemeral: true });
await interaction.editReply({
content: `System '${selectedSystemName}' not found.`,
ephemeral: true,
});
return;
}
// Get the available nodes for this system
const availableNodes = await getAvailableNodes(nodeIo, interaction.guild.id, system);
const availableNodes = await getAvailableNodes(
nodeIo,
interaction.guild.id,
system,
);
// Check if there are available nodes
if (availableNodes.length === 0) {
// If not, let the user know
await interaction.editReply(`<@${interaction.member.id}>, the selected system has no available nodes`);
await interaction.editReply(
`<@${interaction.member.id}>, the selected system has no available nodes`,
);
return;
}
// If there is one available node, request that node join
if (availableNodes.length === 1) {
await joinNode(nodeIo, interaction, availableNodes[0].id, system, channelToJoin);
await joinNode(
nodeIo,
interaction,
availableNodes[0].id,
system,
channelToJoin,
);
}
// If there are more than one available, prompt the user for their selected node
else {
await promptNodeSelection(interaction, availableNodes, async selectedNode => {
await joinNode(nodeIo, interaction, selectedNode, system, channelToJoin);
});
await promptNodeSelection(
interaction,
availableNodes,
async (selectedNode) => {
await joinNode(
nodeIo,
interaction,
selectedNode,
system,
channelToJoin,
);
},
);
}
}
catch (err) {
} catch (err) {
log.ERROR(err);
await interaction.editReply({ content: `An error occurred: ${err.message}`, ephemeral: true });
await interaction.editReply({
content: `An error occurred: ${err.message}`,
ephemeral: true,
});
}
}
}