Merge pull request #15 from voidf1sh/3-0.6

3.0.6 Strain Migration
This commit is contained in:
Skylar Grant 2023-01-07 20:01:02 -05:00 committed by GitHub
commit a0f5465356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 16 deletions

View File

@ -323,11 +323,9 @@ const functions = {
return { embeds: [requestsEmbed], ephemeral: true }; return { embeds: [requestsEmbed], ephemeral: true };
}, },
strain(commandData, message) { strain(strainInfo, interaction) {
const strainEmbed = new Discord.MessageEmbed() const strainEmbed = new Discord.MessageEmbed()
.setTimestamp() .setTimestamp();
.setFooter(commandData.author);
const { strainInfo } = commandData;
strainEmbed.addFields([ strainEmbed.addFields([
{ {
name: 'Strain Name', name: 'Strain Name',
@ -361,7 +359,7 @@ const functions = {
}, },
]); ]);
message.reply({ embeds: [ strainEmbed ]}); interaction.reply({ embeds: [ strainEmbed ]});
}, },
}, },
collect: { collect: {
@ -488,12 +486,11 @@ const functions = {
functions.collections.joints(rows, client); functions.collections.joints(rows, client);
}); });
}, },
strain(commandData, message) { strain(strainName, interaction) {
const { strainName } = commandData;
const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`; const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`;
db.query(query, (err, rows, fields) => { db.query(query, (err, rows, fields) => {
if (rows != undefined) { if (rows != undefined) {
commandData.strainInfo = { const strainInfo = {
id: `${rows[0].id}`, id: `${rows[0].id}`,
strain: `${rows[0].strain}`, strain: `${rows[0].strain}`,
type: `${rows[0].type}`, type: `${rows[0].type}`,
@ -502,7 +499,7 @@ const functions = {
flavor: `${rows[0].flavor}`, flavor: `${rows[0].flavor}`,
rating: `${rows[0].rating}`, rating: `${rows[0].rating}`,
}; };
functions.embeds.strain(commandData, message); functions.embeds.strain(strainInfo, interaction);
} }
}); });
}, },
@ -525,12 +522,7 @@ const functions = {
strain: { strain: {
lookup(strainName, client) { lookup(strainName, client) {
const strainSearcher = new FuzzySearch(client.strains.map(e => e.name)); const strainSearcher = new FuzzySearch(client.strains.map(e => e.name));
const name = strainSearcher.search(strainName)[0]; return strainSearcher.search(strainName).slice(0,25);
if (name != undefined) {
return name;
} else {
return false;
}
}, },
submit(strainName) { submit(strainName) {
const query = `` const query = ``

13
main.js
View File

@ -173,6 +173,19 @@ client.on('interactionCreate', async interaction => {
break; 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 // dot-commands

View File

@ -1,6 +1,6 @@
{ {
"name": "nodbot", "name": "nodbot",
"version": "3.0.5", "version": "3.0.6",
"description": "Nods and Nod Accessories.", "description": "Nods and Nod Accessories.",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {

17
slash-commands/strain.js Normal file
View 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);
},
};