From 4cea0f293c583feb6bb12f9d2308f6bb49eb9108 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sat, 7 Jan 2023 15:27:47 -0500 Subject: [PATCH] Add ability to save new strains --- functions.js | 19 ++++++++++++++- slash-commands/savestrain.js | 47 ++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/functions.js b/functions.js index 70aec19..919ce0e 100644 --- a/functions.js +++ b/functions.js @@ -351,7 +351,7 @@ const functions = { }, { name: 'Rating', - value: `${strainInfo.rating}⭐️s`, + value: `⭐️${strainInfo.rating}`, inline: true, }, { @@ -440,6 +440,23 @@ const functions = { if (err) throw err; functions.download.medicalAdvice(client); }); + }, + strain(interaction) { + const strain = db.escape(interaction.options.getString('name')); + const type = db.escape(interaction.options.getString('type')); + const effects = db.escape(( interaction.options.getString('effects') || 'Unkown' )); + const description = db.escape(( interaction.options.getString('description') || 'Unknown' )); + const flavor = db.escape(( interaction.options.getString('flavor') || 'Unknown' )); + const rating = db.escape(( interaction.options.getString('rating') || '3' )); + const strainQuery = `INSERT INTO strains (strain, type, effects, description, flavor, rating) VALUES (${strain}, ${type}, ${effects}, ${description}, ${flavor}, ${rating})`; + console.log(strainQuery); + return new Promise((resolve, reject) => { + db.query(strainQuery, (err, rows, fields) => { + if (err) reject(err); + functions.download.strains(interaction.client); + resolve(); + }); + }) } }, download: { diff --git a/slash-commands/savestrain.js b/slash-commands/savestrain.js index 662d301..3cc90f8 100644 --- a/slash-commands/savestrain.js +++ b/slash-commands/savestrain.js @@ -2,16 +2,53 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const fn = require('../functions.js'); const { emoji } = require('../strings.json'); +// Strain Name | Type | Effects | Flavor | Rating | Description + module.exports = { data: new SlashCommandBuilder() .setName('savestrain') .setDescription('Store a new Strain in the database!') .addStringOption(option => - option.setName('strain-name') - .setDescription('What is the phrase?') - .setRequired(true)), + option.setName('name') + .setDescription('Name of the Strain') + .setRequired(true)) + .addStringOption(option => + option.setName('type') + .setDescription('Indica/Sativa/Hybrid') + .setRequired(true) + .addChoices( + { name: "Indica", value: "Indica" }, + { name: "Hybrid", value: "Hybrid" }, + { name: "Sativa", value: "Sativa" } + )) + .addStringOption(option => + option.setName('effects') + .setDescription('The effects given by the strain') + .setRequired(false)) + .addStringOption(option => + option.setName('flavor') + .setDescription('Flavor notes') + .setRequired(false)) + .addStringOption(option => + option.setName('rating') + .setDescription('Number of stars') + .setRequired(false)) + .addStringOption(option => + option.setName('description') + .setDescription('Description of the strain') + .setRequired(false)), async execute(interaction) { - fn.upload.joint(interaction.options.getString('joint-content'), interaction.client); - interaction.reply({ content: `The joint has been rolled${emoji.joint}`, ephemeral: true }); + fn.upload.strain(interaction).then(res => { + interaction.reply({ + content: `The strain information has been saved. (${interaction.options.getString('name')})`, + ephemeral: true + }); + }).catch(err => { + console.log(`E: ${err}`); + interaction.reply({ + content: 'There was a problem saving the strain.', + ephemeral: true + }); + }); }, }; \ No newline at end of file