From 8eea3e005dab2f732ebd9d6fd38baa54db7fadd1 Mon Sep 17 00:00:00 2001 From: ShuriZma Date: Fri, 7 Jun 2024 09:24:06 +0200 Subject: [PATCH] add fake field to show that a fact is fake --- src/bot.ts | 10 ++++++++-- src/commands/addFact.ts | 14 ++++++++++++-- src/commands/editFact.ts | 10 +++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index ece10d3..190ee1b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -117,7 +117,7 @@ export class Bot { port: config.dbPort, }) - this.connection.execute('CREATE TABLE if NOT EXISTS facts (id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, content TEXT NOT NULL, active TINYINT(1) NOT NULL DEFAULT 1, counter INT UNSIGNED NOT NULL DEFAULT 0);'); + this.connection.execute('CREATE TABLE if NOT EXISTS facts (id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, content TEXT NOT NULL, active TINYINT(1) NOT NULL DEFAULT 1, fake TINYINT(1) NOT NULL DEFAULT 1, counter INT UNSIGNED NOT NULL DEFAULT 0);'); if (closeConnection) { this.endConection(); @@ -168,13 +168,19 @@ export class Bot { inline: true, }); + fields.push({ + name: 'fake', + value: result.fake ? 'True' : 'False', + inline: true, + }); + fields.push({ name: 'counter', value: result.counter.toString(), inline: true, }); - if (fields.length < 24) { + if (fields.length < 20) { continue; } diff --git a/src/commands/addFact.ts b/src/commands/addFact.ts index 935584a..84cae2a 100644 --- a/src/commands/addFact.ts +++ b/src/commands/addFact.ts @@ -17,18 +17,28 @@ const activeOption = (new SlashCommandBooleanOption()) .setDescription('Should the fact be used?') .setRequired(false); +const fakeOption = (new SlashCommandBooleanOption()) + .setName('fake') + .setDescription('Is this a fake fact?') + .setRequired(false); + export default { data: new SlashCommandBuilder() .setName('addfact') .setDescription('Add a logtastic fact.') .addStringOption(factOption) .addBooleanOption(activeOption) + .addBooleanOption(fakeOption) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), execute: async function (interaction: ChatInputCommandInteraction) { const bot = Bot.getInstance(); await bot.getConnection().promise().execute( - 'INSERT INTO facts SET content = ?, active = ?;', - [interaction.options.data.at(0).value, interaction.options.data.at(1)?.value ?? true] + 'INSERT INTO facts SET content = ?, active = ?, fake = ?;', + [ + interaction.options.data.at(0).value, + interaction.options.data.at(1)?.value ?? true, + interaction.options.data.at(2)?.value ?? false, + ] ); bot.endConection(); console.log('Fact has been saved!'); diff --git a/src/commands/editFact.ts b/src/commands/editFact.ts index 9f385f4..30389c1 100644 --- a/src/commands/editFact.ts +++ b/src/commands/editFact.ts @@ -22,6 +22,11 @@ const activeOption = (new SlashCommandBooleanOption()) .setDescription('Should the fact be enabled?') .setRequired(false); +const fakeOption = (new SlashCommandBooleanOption()) + .setName('fake') + .setDescription('Is this a fake fact?') + .setRequired(false); + export default { data: new SlashCommandBuilder() .setName('editfact') @@ -29,15 +34,18 @@ export default { .addIntegerOption(idOption) .addStringOption(factOption) .addBooleanOption(activeOption) + .addBooleanOption(fakeOption) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), execute: async function (interaction: ChatInputCommandInteraction) { const bot = Bot.getInstance(); await bot.getConnection().promise().execute( - 'UPDATE facts SET content = ?, active = IF(? != NULL, ?, active) WHERE id = ?;', + 'UPDATE facts SET content = ?, active = IF(? != NULL, ?, active), fake = IF(? != NULL, ?, fake) WHERE id = ?;', [ interaction.options.data.at(1).value, interaction.options.data.at(2)?.value ?? null, interaction.options.data.at(2)?.value ?? null, + interaction.options.data.at(3)?.value ?? null, + interaction.options.data.at(3)?.value ?? null, interaction.options.data.at(0).value, ] );