Basic implementation of variadic list inputs

This commit is contained in:
Nathaniel Mason 2022-04-22 06:11:53 +01:00
parent ab2cd6bd7d
commit 37e0603ebf
4 changed files with 39 additions and 24 deletions

View File

@ -1,8 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Give some lines of input, and get one back at random', description: 'Give some lines of input, and get one back at random',
options: [], options: [...Array(10).keys()].map(i => ({
name: `option${i + 1}`,
description: 'Another option',
required: false,
type: Constants.ApplicationCommandOptionTypes.STRING
})),
async parseMessage (client, config, message, args) { async parseMessage (client, config, message, args) {
let [head, ...options] = message.content.split(/\s*\n\s*/); let [head, ...options] = message.content.split(/\s*\n\s*/);
@ -11,9 +18,8 @@ module.exports = {
await message.channel.send(this.handle(client, config, message.author, options)); await message.channel.send(this.handle(client, config, message.author, options));
}, },
// TODO: Figure out variable input
async parseInteraction (client, config, interaction) { async parseInteraction (client, config, interaction) {
await interaction.reply(this.handle(client, config, interaction.user, interaction.options.getString('question'))); await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`))));
}, },
handle (client, config, user, options) { handle (client, config, user, options) {

View File

@ -1,16 +1,22 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Reloads a command', description: 'Reloads a command',
options: [], options: [...Array(10).keys()].map(i => ({
name: `option${i + 1}`,
description: 'Another option',
required: false,
type: Constants.ApplicationCommandOptionTypes.STRING
})),
async parseMessage (client, config, message, args) { async parseMessage (client, config, message, args) {
await message.channel.send(this.handle(client, config, message.author, args.split(' '))); await message.channel.send(this.handle(client, config, message.author, args.split(' ')));
}, },
// TODO: figure out variable input (again)
async parseInteraction (client, config, interaction) { async parseInteraction (client, config, interaction) {
await interaction.reply(this.handle(client, config, interaction.user)); await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`))));
}, },
handle (client, config, user, args) { handle (client, config, user, args) {

View File

@ -5,6 +5,8 @@
"release": "anitrox_dev", "release": "anitrox_dev",
"build": "Stable", "build": "Stable",
"footerTxt": "Anitrox, made with <3 by IDeletedSystem64 | 2018-2022", "footerTxt": "Anitrox, made with <3 by IDeletedSystem64 | 2018-2022",
"sandbox": false,
"sandboxGuild": "Set the value above to true and put a server ID here to use local slash commands instead of global. Used for debugging purposes",
"statuses": [ "statuses": [
"with np!help", "with np!help",

View File

@ -32,28 +32,29 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({
client.on('error', (e) => console.log(`[ERROR] ${e}`)); client.on('error', (e) => console.log(`[ERROR] ${e}`));
client.on('warn', (e) => (`[WARN] ${e}`)); client.on('warn', (e) => (`[WARN] ${e}`));
client.once('ready', async () => { client.once('ready', async () => {
// const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands; const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands;
// if (config.sandbox) { // Be careful about running the code below, there's a 200-per-day limit on creating slash commands
// console.log('deleting previous commands from sandbox'); if (config.sandbox) {
// const localCommands = await commands.fetch(); console.log('deleting previous commands from sandbox');
// localCommands.forEach(async x => { const localCommands = await commands.fetch();
// await commands.delete(x); localCommands.forEach(async x => {
// }); await commands.delete(x);
});
// console.log('deleting global commands'); console.log('deleting global commands');
// const globalCommands = await client.application.commands.fetch(); const globalCommands = await client.application.commands.fetch();
// globalCommands.forEach(async x => { globalCommands.forEach(async x => {
// await client.application.commands.delete(x); await client.application.commands.delete(x);
// }); });
// } }
// client.commands.forEach(async command => { client.commands.forEach(async command => {
// await commands.create(command); await commands.create(command);
// console.log(command); console.log(command);
// }); });
// console.clear(); console.clear();
console.log(' ___ _ __ '); console.log(' ___ _ __ ');
console.log(' / | ____ (_) /__________ _ __'); console.log(' / | ____ (_) /__________ _ __');
console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/'); console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/');