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,
})
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;
}

View File

@ -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!');

View File

@ -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,
]
);