From c600aa30bd8b1a8cd9cf09009f194297bf831287 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sat, 7 Jan 2023 19:29:13 -0500 Subject: [PATCH 1/2] Versioning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bd982e..d9d7146 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodbot", - "version": "3.0.5", + "version": "3.0.6", "description": "Nods and Nod Accessories.", "main": "main.js", "dependencies": { From 5d33431d275a8aeee853a89dd04490e6fd6be28c Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sat, 7 Jan 2023 20:00:15 -0500 Subject: [PATCH 2/2] Move strain to slash, add autocomplete --- dot-commands/{strain.js => strain.js.bak} | 0 functions.js | 22 +++++++--------------- main.js | 13 +++++++++++++ slash-commands/strain.js | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 15 deletions(-) rename dot-commands/{strain.js => strain.js.bak} (100%) create mode 100644 slash-commands/strain.js diff --git a/dot-commands/strain.js b/dot-commands/strain.js.bak similarity index 100% rename from dot-commands/strain.js rename to dot-commands/strain.js.bak diff --git a/functions.js b/functions.js index 919ce0e..72e9c65 100644 --- a/functions.js +++ b/functions.js @@ -323,11 +323,9 @@ const functions = { return { embeds: [requestsEmbed], ephemeral: true }; }, - strain(commandData, message) { + strain(strainInfo, interaction) { const strainEmbed = new Discord.MessageEmbed() - .setTimestamp() - .setFooter(commandData.author); - const { strainInfo } = commandData; + .setTimestamp(); strainEmbed.addFields([ { name: 'Strain Name', @@ -361,7 +359,7 @@ const functions = { }, ]); - message.reply({ embeds: [ strainEmbed ]}); + interaction.reply({ embeds: [ strainEmbed ]}); }, }, collect: { @@ -488,12 +486,11 @@ const functions = { functions.collections.joints(rows, client); }); }, - strain(commandData, message) { - const { strainName } = commandData; + strain(strainName, interaction) { const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`; db.query(query, (err, rows, fields) => { if (rows != undefined) { - commandData.strainInfo = { + const strainInfo = { id: `${rows[0].id}`, strain: `${rows[0].strain}`, type: `${rows[0].type}`, @@ -502,7 +499,7 @@ const functions = { flavor: `${rows[0].flavor}`, rating: `${rows[0].rating}`, }; - functions.embeds.strain(commandData, message); + functions.embeds.strain(strainInfo, interaction); } }); }, @@ -525,12 +522,7 @@ const functions = { strain: { lookup(strainName, client) { const strainSearcher = new FuzzySearch(client.strains.map(e => e.name)); - const name = strainSearcher.search(strainName)[0]; - if (name != undefined) { - return name; - } else { - return false; - } + return strainSearcher.search(strainName).slice(0,25); }, submit(strainName) { const query = `` diff --git a/main.js b/main.js index 85c118e..f215e21 100644 --- a/main.js +++ b/main.js @@ -173,6 +173,19 @@ client.on('interactionCreate', async interaction => { break; } } + + // Handle autocomplete requests + if (interaction.isAutocomplete()) { + if (interaction.commandName == 'strain') { + const searchString = interaction.options.getFocused(); + const choices = fn.weed.strain.lookup(searchString, interaction.client); + await interaction.respond( + choices.map(choice => ({ name: choice, value: choice })) + ) + } else { + return; + } + } }); // dot-commands diff --git a/slash-commands/strain.js b/slash-commands/strain.js new file mode 100644 index 0000000..74cf8d3 --- /dev/null +++ b/slash-commands/strain.js @@ -0,0 +1,17 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const fn = require('../functions.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('strain') + .setDescription('Look up information about a cannabis strain.') + .addStringOption(option => + option + .setName('name') + .setDescription('Strain Name') + .setRequired(true) + .setAutocomplete(true)), + async execute(interaction) { + fn.download.strain(interaction.options.getString('name'), interaction); + }, +}; \ No newline at end of file