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 { StrainData: class {
constructor() { constructor() {
this.id = 0; this.id = 0;
this.name = ""; this.name = "Unknown";
this.type = ""; this.type = "Unknown";
this.effects = ""; this.effects = "Unknown";
this.flavor = ""; this.flavor = "Unknown";
this.rating = "0.0"; this.rating = "0.0";
this.description = ""; this.description = "Unknown";
} }
// Initial Strain configuration // Initial Strain configuration

View File

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

View File

@ -165,6 +165,8 @@ module.exports = {
description: interaction.options.getString('description') description: interaction.options.getString('description')
}; };
const strainData = new StrainData().setInfo(interaction.options.getString('name'), details); 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) .setRequired(true)
.setAutocomplete(true)), .setAutocomplete(true)),
async execute(interaction) { 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);
}, },
}; };