diff --git a/discordBot/commands/connections.mjs b/discordBot/commands/connections.mjs new file mode 100644 index 0000000..da89a03 --- /dev/null +++ b/discordBot/commands/connections.mjs @@ -0,0 +1,52 @@ +import { DebugBuilder } from "../../modules/debugger.mjs"; +const log = new DebugBuilder("server", "discordBot.command.ping"); +import { SlashCommandBuilder } from 'discord.js'; + +// Exporting data property that contains the command structure for discord including any params +export const data = new SlashCommandBuilder() + .setName('connections') + .setDescription('Check to see what bots are online.'); + +// Exporting other properties +export const example = "/connections"; // 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 = []; // The array to be filled with the autocorrect values + const filtered = choices.filter(choice => choice.name.startsWith(focusedValue)); + log.INFO(focusedValue, choices, filtered); + await interaction.respond(filtered.map(choice => ({name: choice.name, value: choice.name}))); +} +*/ + +/** + * 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 sockets = await nodeIo.allSockets(); + log.DEBUG("All open sockets: ",sockets); + let socketMessage = ""; + + // Create the message for discord with each socket on a new line + sockets.forEach(socket => { + socketMessage += `\n${socket}` + }); + + await interaction.reply(`**Online Sockets: '${socketMessage}'**`); + //await interaction.reply('**Pong.**'); + //await interaction.channel.send('**Pong.**'); + } catch (err) { + console.error(err); + // await interaction.reply(err.toString()); + } +} \ No newline at end of file