From 93626ff8e569c300c3d7c082c7c8369b9b08114b Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 8 Aug 2023 17:16:05 -0400 Subject: [PATCH] /save is broken, /edit still needs work --- functions.js | 24 ++++++++++++------------ main.js | 26 +++++++++++++++++--------- slash-commands/save.js | 14 ++++++++++++-- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/functions.js b/functions.js index 27f547a..a44123b 100644 --- a/functions.js +++ b/functions.js @@ -496,16 +496,16 @@ const functions = { } }, download: { - requests(client) { + async requests(client) { const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id DESC'; - db.query(query, (err, rows, fields) => { + await db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.requests(rows, client); }); }, - pastas(client) { + async pastas(client) { const query = 'SELECT * FROM pastas ORDER BY id ASC'; - db.query(query, (err, rows, fields) => { + await db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.pastas(rows, client); }); @@ -517,16 +517,16 @@ const functions = { functions.collections.gifs(rows, client); }); }, - joints(client) { + async joints(client) { const query = 'SELECT * FROM joints ORDER BY id ASC'; - db.query(query, (err, rows, fields) => { + await db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.joints(rows, client); }); }, - strain(strainName, interaction) { + async 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) => { + await db.query(query, (err, rows, fields) => { if (rows != undefined) { const strainInfo = { id: `${rows[0].id}`, @@ -541,16 +541,16 @@ const functions = { } }); }, - strains(client) { + async strains(client) { const query = 'SELECT * FROM strains'; - db.query(query, (err, rows, fields) => { + await db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.strains(rows, client); }); }, - medicalAdvice(client) { + async medicalAdvice(client) { const query = 'SELECT * FROM medical_advice ORDER BY id ASC'; - db.query(query, (err, rows, fields) => { + await db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.medicalAdvice(rows, client); }); diff --git a/main.js b/main.js index ed084ef..b959c78 100644 --- a/main.js +++ b/main.js @@ -30,18 +30,18 @@ const strings = require('./strings.json'); const { GifData } = require('./CustomModules/NodBot.js'); const isDev = process.env.isDev; -client.once('ready', () => { +client.once('ready', async () => { fn.collections.slashCommands(client); fn.collections.dotCommands(client); fn.collections.setvalidCommands(client); - fn.download.gifs(client); - fn.download.pastas(client); - fn.download.joints(client); - fn.download.requests(client); - fn.download.strains(client); - fn.download.medicalAdvice(client); + await fn.download.gifs(client); + await fn.download.pastas(client); + await fn.download.joints(client); + await fn.download.requests(client); + await fn.download.strains(client); + await fn.download.medicalAdvice(client); console.log('Ready!'); - client.channels.fetch(statusChannelId).then(channel => { + await client.channels.fetch(statusChannelId).then(channel => { channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); }); }); @@ -203,7 +203,15 @@ client.on('interactionCreate', async interaction => { pastaChoices.map(choice => ({ name: choice, value: choice })) ); break; - + case "strain": + //TODO + const strainQuery = interaction.options.getFocused(); + const strainChoices = fn.weed.strain.lookup(strainQuery, interaction.client); + await interaction.respond( + strainChoices.map(choice => ({ name: choice, value: choice })) + ); + break; + default: break; } diff --git a/slash-commands/save.js b/slash-commands/save.js index 6390e8b..c209cba 100644 --- a/slash-commands/save.js +++ b/slash-commands/save.js @@ -10,7 +10,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { MessageActionRow, MessageButton } = require('discord.js'); const fn = require('../functions.js'); const strings = require('../strings.json'); -const { GifData } = require('../CustomModules/NodBot.js'); +const { GifData, StrainData } = require('../CustomModules/NodBot.js'); const { emoji } = strings; module.exports = { @@ -213,7 +213,17 @@ module.exports = { // Strain case "strain": //TODO - fn.upload.strain(interaction).then(res => { + const strainData = new StrainData().setInfo( + interaction.options.getString('name'), + { + type: interaction.options.getString('type'), + effects: interaction.options.getString('effects'), + flavor: interaction.options.getString('flavor'), + rating: interaction.options.getString('rating'), + description: interaction.options.getString('description') + } + ); + fn.upload.strain(interaction, strainData).then(res => { interaction.editReply({ content: `The strain information has been saved. (${interaction.options.getString('name')})`, ephemeral: true