Move strain to slash, add autocomplete
This commit is contained in:
parent
c600aa30bd
commit
5d33431d27
22
functions.js
22
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 = ``
|
||||
|
13
main.js
13
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
|
||||
|
17
slash-commands/strain.js
Normal file
17
slash-commands/strain.js
Normal file
@ -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);
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user