3 Commits

Author SHA1 Message Date
Logan Cusano
fc11324714 Add function to get all client IDs from JSON file #7 2023-06-04 00:24:50 -04:00
Logan Cusano
c6c048c919 Update default command with autocomplete 2023-06-03 23:35:07 -04:00
Logan Cusano
8ab611836b Allow commands to use autocomplete 2023-06-03 23:31:27 -04:00
4 changed files with 57 additions and 37 deletions

View File

@@ -1,11 +1,9 @@
// Modules
const { customSlashCommandBuilder } = require('../utilities/customSlashCommandBuilder');
const { DebugBuilder } = require("../utilities/debugBuilder");
const { BufferToJson, getMembersInRole, getKeyByArrayValue } = require("../utilities/utils");
const { getMembersInRole, getAllClientIds } = require("../utilities/utils");
const { requestOptions, sendHttpRequest } = require("../utilities/httpRequests");
const { readFileSync } = require('fs');
const { getOnlineNodes, getNodeInfoFromId, updateNodeInfo } = require("../utilities/mysqlHandler");
const path = require('path');
const { getOnlineNodes, updateNodeInfo } = require("../utilities/mysqlHandler");
// Global Vars
const log = new DebugBuilder("server", "join");
@@ -44,7 +42,7 @@ async function joinServerWrapper(presetName, channelId, clientIdsUsed) {
if (!nodesCurrentlyAvailable.length > 0) return Error("All nodes with this channel are unavailable, consider swapping one of the currently joined bots.");
// If so, join with the first node
var availableClientIds = await Object(JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json'))));
var availableClientIds = await getAllClientIds();
log.DEBUG("All clients: ", Object.keys(availableClientIds));
var selectedClientId;

View File

@@ -18,6 +18,9 @@ module.exports = {
requiresTokens: false,
defaultTokenUsage: 0,
deferInitialReply: false,
/*async autocomplete(interaction) {
const focusedValue = interaction.options.getFocused();
},*/
async execute(interaction) {
try{
await interaction.channel.send('**Pong.**'); // TODO - Add insults as the response to this command

View File

@@ -8,9 +8,17 @@ const log = new DebugBuilder("server", "interactionCreate");
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
log.VERBOSE("Interaction for command: ", command);
// Execute autocomplete if the user is checking autocomplete
if (interaction.isAutocomplete()) {
log.DEBUG("Running autocomplete for command: ", command.data.name);
return await command.autocomplete(interaction);
}
// Check if the interaction is a command
if (!interaction.isChatInputCommand()) return;
if (!command) {
log.ERROR(`No command matching ${interaction.commandName} was found.`);

View File

@@ -1,6 +1,8 @@
// Debug
const { DebugBuilder } = require("../utilities/debugBuilder");
const { readFileSync } = require('fs');
const log = new DebugBuilder("server", "utils");
const path = require('path');
// Convert a JSON object to a buffer for the DB
exports.JsonToBuffer = (jsonObject) => {
@@ -73,3 +75,12 @@ exports.isJsonString = (str) => {
}
return true;
}
/**
* Get all client IDs from the saved JSON file
*
* @returns Object of Client IDs
*/
exports.getAllClientIds = () => {
return Object(JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json'))));
}