New entries are being created, check keys

This commit is contained in:
Skylar Grant 2023-08-08 19:35:36 -04:00
parent 93626ff8e5
commit 8b2768bc12
4 changed files with 31 additions and 23 deletions

View File

@ -53,12 +53,12 @@ module.exports = {
StrainData: class {
constructor() {
this.id = 0;
this.name = "";
this.type = "";
this.effects = "";
this.flavor = "";
this.name = "Unknown";
this.type = "Unknown";
this.effects = "Unknown";
this.flavor = "Unknown";
this.rating = "0.0";
this.description = "";
this.description = "Unknown";
}
// Initial Strain configuration

View File

@ -372,7 +372,7 @@ const functions = {
},
]);
interaction.reply({ embeds: [ strainEmbed ]});
return { embeds: [ strainEmbed ]};
},
dalle(prompt, imageUrl, size) {
const dalleEmbed = new Discord.MessageEmbed()
@ -478,7 +478,7 @@ const functions = {
});
},
strain(interaction, strainData) {
const strainQuery = `INSERT INTO strains (strain, type, effects, description, flavor, rating) VALUES (${db.escape(strainData.name)}, ${db.escape(strainData.type)}, ${db.escape(strainData.effects)}, ${db.escape(strainData.description)}, ${db.escape(strainData.flavor)}, ${db.escape(strainData.rating)}) ON DUPLICATE KEY UPDATE strain=${db.escape(strainData.strain)}, type=${db.escape(strainData.type)}, effects=${db.escape(strainData.effects)}, description=${db.escape(strainData.description)}, flavor=${db.escape(strainData.flavor)}, rating=${db.escape(strainData.rating)}`;
const strainQuery = `INSERT INTO strains (strain, type, effects, description, flavor, rating) VALUES (${db.escape(strainData.name)}, ${db.escape(strainData.type)}, ${db.escape(strainData.effects)}, ${db.escape(strainData.description)}, ${db.escape(strainData.flavor)}, ${db.escape(strainData.rating)}) ON DUPLICATE KEY UPDATE type=${db.escape(strainData.type)}, effects=${db.escape(strainData.effects)}, description=${db.escape(strainData.description)}, flavor=${db.escape(strainData.flavor)}, rating=${db.escape(strainData.rating)}`;
console.log(strainQuery);
return new Promise((resolve, reject) => {
db.query(strainQuery, (err, rows, fields) => {
@ -525,21 +525,25 @@ const functions = {
});
},
async strain(strainName, interaction) {
const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`;
await db.query(query, (err, rows, fields) => {
if (rows != undefined) {
const strainInfo = {
id: `${rows[0].id}`,
strain: `${rows[0].strain}`,
type: `${rows[0].type}`,
effects: `${rows[0].effects}`,
description: `${rows[0].description}`,
flavor: `${rows[0].flavor}`,
rating: `${rows[0].rating}`,
};
functions.embeds.strain(strainInfo, interaction);
}
return new Promise(async (resolve, reject) => {
const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`;
await db.query(query, (err, rows, fields) => {
if (rows != undefined) {
const strainInfo = {
id: `${rows[0].id}`,
strain: `${rows[0].strain}`,
type: `${rows[0].type}`,
effects: `${rows[0].effects}`,
description: `${rows[0].description}`,
flavor: `${rows[0].flavor}`,
rating: `${rows[0].rating}`,
};
const embed = functions.embeds.strain(strainInfo, interaction);
resolve(embed);
}
});
});
},
async strains(client) {
const query = 'SELECT * FROM strains';

View File

@ -165,6 +165,8 @@ module.exports = {
description: interaction.options.getString('description')
};
const strainData = new StrainData().setInfo(interaction.options.getString('name'), details);
await fn.upload.strain(interaction);
await fn.upload.strain(interaction, strainData);
const reply = await fn.download.strain(strainData.name, interaction);
await interaction.editReply(reply);
}
};

View File

@ -12,6 +12,8 @@ module.exports = {
.setRequired(true)
.setAutocomplete(true)),
async execute(interaction) {
fn.download.strain(interaction.options.getString('name'), interaction);
await interaction.deferReply();
const reply = await fn.download.strain(interaction.options.getString('name'), interaction);
await interaction.editReply(reply);
},
};