Add ability to save new strains
This commit is contained in:
parent
eef5258519
commit
4cea0f293c
19
functions.js
19
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: {
|
||||
|
@ -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
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user