add edit command

This commit is contained in:
ShuriZma 2024-06-07 09:07:52 +02:00
parent c777b4c358
commit 0f473aecc6
Signed by: ShuriZma
GPG Key ID: 8D289758EE9B8074
2 changed files with 55 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import Fact from "./commands/fact";
import AddFact from "./commands/addFact";
import RemoveFact from "./commands/removeFact";
import EnableFact from "./commands/enableFact";
import EditFact from "./commands/editFact";
import Facts from "./commands/facts";
import {pagination} from "@devraelfreeze/discordjs-pagination";
@ -35,6 +36,7 @@ export class Bot {
commands.set(AddFact.data.name, AddFact);
commands.set(RemoveFact.data.name, RemoveFact);
commands.set(EnableFact.data.name, EnableFact);
commands.set(EditFact.data.name, EditFact);
commands.set(Facts.data.name, Facts);
@ -83,6 +85,7 @@ export class Bot {
AddFact.data.toJSON(),
RemoveFact.data.toJSON(),
EnableFact.data.toJSON(),
EditFact.data.toJSON(),
Facts.data.toJSON(),
);

52
src/commands/editFact.ts Normal file
View File

@ -0,0 +1,52 @@
import {
ChatInputCommandInteraction,
PermissionsBitField,
SlashCommandBooleanOption,
SlashCommandBuilder, SlashCommandIntegerOption,
SlashCommandStringOption,
} from 'discord.js';
import {Bot} from "../bot";
const idOption = (new SlashCommandIntegerOption())
.setName('id')
.setDescription('The id of the fact that should be removed.')
.setRequired(true);
const factOption = (new SlashCommandStringOption())
.setName('fact')
.setDescription('The fact.')
.setRequired(true);
const activeOption = (new SlashCommandBooleanOption())
.setName('active')
.setDescription('Should the fact be enabled?')
.setRequired(false);
export default {
data: new SlashCommandBuilder()
.setName('editfact')
.setDescription('Edit a logtastic fact.')
.addIntegerOption(idOption)
.addStringOption(factOption)
.addBooleanOption(activeOption)
.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 = ?;',
[
interaction.options.data.at(1).value,
interaction.options.data.at(2)?.value ?? null,
interaction.options.data.at(2)?.value ?? null,
interaction.options.data.at(0).value,
]
);
bot.endConection();
console.log('Fact has been saved!');
return await interaction.reply({
content: 'Done!',
ephemeral: true,
});
},
};