add fake field to show that a fact is fake

This commit is contained in:
ShuriZma 2024-06-07 09:24:06 +02:00
parent 0f473aecc6
commit 8eea3e005d
Signed by: ShuriZma
GPG Key ID: 8D289758EE9B8074
3 changed files with 29 additions and 5 deletions

View File

@ -117,7 +117,7 @@ export class Bot {
port: config.dbPort, 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) { if (closeConnection) {
this.endConection(); this.endConection();
@ -168,13 +168,19 @@ export class Bot {
inline: true, inline: true,
}); });
fields.push({
name: 'fake',
value: result.fake ? 'True' : 'False',
inline: true,
});
fields.push({ fields.push({
name: 'counter', name: 'counter',
value: result.counter.toString(), value: result.counter.toString(),
inline: true, inline: true,
}); });
if (fields.length < 24) { if (fields.length < 20) {
continue; continue;
} }

View File

@ -17,18 +17,28 @@ const activeOption = (new SlashCommandBooleanOption())
.setDescription('Should the fact be used?') .setDescription('Should the fact be used?')
.setRequired(false); .setRequired(false);
const fakeOption = (new SlashCommandBooleanOption())
.setName('fake')
.setDescription('Is this a fake fact?')
.setRequired(false);
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('addfact') .setName('addfact')
.setDescription('Add a logtastic fact.') .setDescription('Add a logtastic fact.')
.addStringOption(factOption) .addStringOption(factOption)
.addBooleanOption(activeOption) .addBooleanOption(activeOption)
.addBooleanOption(fakeOption)
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
execute: async function (interaction: ChatInputCommandInteraction) { execute: async function (interaction: ChatInputCommandInteraction) {
const bot = Bot.getInstance(); const bot = Bot.getInstance();
await bot.getConnection().promise().execute( await bot.getConnection().promise().execute(
'INSERT INTO facts SET content = ?, active = ?;', 'INSERT INTO facts SET content = ?, active = ?, fake = ?;',
[interaction.options.data.at(0).value, interaction.options.data.at(1)?.value ?? true] [
interaction.options.data.at(0).value,
interaction.options.data.at(1)?.value ?? true,
interaction.options.data.at(2)?.value ?? false,
]
); );
bot.endConection(); bot.endConection();
console.log('Fact has been saved!'); console.log('Fact has been saved!');

View File

@ -22,6 +22,11 @@ const activeOption = (new SlashCommandBooleanOption())
.setDescription('Should the fact be enabled?') .setDescription('Should the fact be enabled?')
.setRequired(false); .setRequired(false);
const fakeOption = (new SlashCommandBooleanOption())
.setName('fake')
.setDescription('Is this a fake fact?')
.setRequired(false);
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('editfact') .setName('editfact')
@ -29,15 +34,18 @@ export default {
.addIntegerOption(idOption) .addIntegerOption(idOption)
.addStringOption(factOption) .addStringOption(factOption)
.addBooleanOption(activeOption) .addBooleanOption(activeOption)
.addBooleanOption(fakeOption)
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
execute: async function (interaction: ChatInputCommandInteraction) { execute: async function (interaction: ChatInputCommandInteraction) {
const bot = Bot.getInstance(); const bot = Bot.getInstance();
await bot.getConnection().promise().execute( 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(1).value,
interaction.options.data.at(2)?.value ?? null, interaction.options.data.at(2)?.value ?? null,
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, interaction.options.data.at(0).value,
] ]
); );