Files
DRBv3/server/discordBot/commands/update.mjs
Logan Cusano 7efd0cd4f3 Fixed a bug in server update command #10
- Didn't properly get the open sockets
2024-03-03 21:31:14 -05:00

35 lines
1.6 KiB
JavaScript

import { SlashCommandBuilder } from 'discord.js';
import { requestNodeUpdate } from '../../modules/socketServerWrappers.mjs';
// Exporting data property that contains the command structure for discord including any params
export const data = new SlashCommandBuilder()
.setName('update')
.setDescription('Updates all nodes currently logged on');
// Exporting other properties
export const example = "/update"; // 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.
/**
* 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 {
const openSockets = [...await nodeIo.allSockets()]; // TODO - Filter the returned nodes to only nodes that have the radio capability
console.log("All open sockets: ", openSockets);
// Check each open socket to see if the node has the requested system
await Promise.all(openSockets.map(openSocket => {
openSocket = nodeIo.sockets.sockets.get(openSocket);
requestNodeUpdate(openSocket);
}));
//await interaction.reply(`**Online Sockets: '${sockets}'**`);
await interaction.reply('All nodes have been requested to update');
//await interaction.channel.send('**Pong.**');
} catch (err) {
console.error(err);
// await interaction.reply(err.toString());
}
}