Files
DRB-CnC/Server/utilities/customSlashCommandBuilder.js
Logan Cusano d2186e9471 Added a join command #7
- Added a JSON example for Known Client IDs
- Implemented a custom slash command builder to add the available presets as options in the discord command
2023-06-03 15:47:07 -04:00

87 lines
3.2 KiB
JavaScript

const { SlashCommandBuilder, SlashCommandStringOption } = require('discord.js');
const { DebugBuilder } = require("../utilities/debugBuilder");
const { BufferToJson } = require("../utilities/utils");
const log = new DebugBuilder("server", "customSlashCommandBuilder");
const { getAllNodes, getAllNodesSync } = require("../utilities/mysqlHandler");
exports.customSlashCommandBuilder = class customSlashCommandBuilder extends SlashCommandBuilder {
constructor() {
super();
}
async addAllSystemPresetOptions() {
const nodeObjects = await new Promise((recordResolve, recordReject) => {
getAllNodes((nodeRows) => {
recordResolve(nodeRows);
});
});
log.DEBUG("Node objects: ", nodeObjects);
var presetsAvailable = [];
for (const nodeObject of nodeObjects) {
log.DEBUG("Node object: ", nodeObject);
for (const presetName in nodeObject.nearbySystems) presetsAvailable.push(nodeObject.nearbySystems[presetName]);
}
log.DEBUG("All Presets available: ", presetsAvailable);
// Remove duplicates
presetsAvailable = [...new Set(presetsAvailable)];
log.DEBUG("DeDuped Presets available: ", presetsAvailable);
this.addStringOption(option => option.setName("preset").setRequired(true).setDescription("The channels"));
for (const preset of presetsAvailable){
log.DEBUG("Preset: ", preset);
this.options[0].addChoices({
'name': String(preset),
'value': String(preset)
});
}
log.DEBUG("Preset Options: ", this);
return this;
}
/*
return new class extends SlashCommandStringOption {
constructor() {
super();
getAllNodes((nodeObjects) => {
this.name = "preset"
this.required = "false"
var presetsAvailable = [];
for (const nodeObject of nodeObjects) {
nodeObject.nearbySystems = BufferToJson(nodeObject.nearbySystems);
log.DEBUG("Node object: ", nodeObject);
for (const presetName in nodeObject.nearbySystems) presetsAvailable.push(nodeObject.nearbySystems[presetName]);
}
log.DEBUG("All Presets available: ", presetsAvailable);
// Remove duplicates
presetsAvailable = [...new Set(presetsAvailable)];
log.DEBUG("DeDuped Presets available: ", presetsAvailable);
var choicesList = []
for (const preset of presetsAvailable){
log.DEBUG("Preset: ", preset);
choicesList.push({
name: preset,
value: preset
})
}
log.DEBUG("Choice List: ", choicesList);
this.choices = JSON.stringify(choicesList);
return this;
});
}
}
*/
}