add edit command
This commit is contained in:
parent
c777b4c358
commit
0f473aecc6
|
@ -18,6 +18,7 @@ import Fact from "./commands/fact";
|
||||||
import AddFact from "./commands/addFact";
|
import AddFact from "./commands/addFact";
|
||||||
import RemoveFact from "./commands/removeFact";
|
import RemoveFact from "./commands/removeFact";
|
||||||
import EnableFact from "./commands/enableFact";
|
import EnableFact from "./commands/enableFact";
|
||||||
|
import EditFact from "./commands/editFact";
|
||||||
import Facts from "./commands/facts";
|
import Facts from "./commands/facts";
|
||||||
import {pagination} from "@devraelfreeze/discordjs-pagination";
|
import {pagination} from "@devraelfreeze/discordjs-pagination";
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ export class Bot {
|
||||||
commands.set(AddFact.data.name, AddFact);
|
commands.set(AddFact.data.name, AddFact);
|
||||||
commands.set(RemoveFact.data.name, RemoveFact);
|
commands.set(RemoveFact.data.name, RemoveFact);
|
||||||
commands.set(EnableFact.data.name, EnableFact);
|
commands.set(EnableFact.data.name, EnableFact);
|
||||||
|
commands.set(EditFact.data.name, EditFact);
|
||||||
commands.set(Facts.data.name, Facts);
|
commands.set(Facts.data.name, Facts);
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +85,7 @@ export class Bot {
|
||||||
AddFact.data.toJSON(),
|
AddFact.data.toJSON(),
|
||||||
RemoveFact.data.toJSON(),
|
RemoveFact.data.toJSON(),
|
||||||
EnableFact.data.toJSON(),
|
EnableFact.data.toJSON(),
|
||||||
|
EditFact.data.toJSON(),
|
||||||
Facts.data.toJSON(),
|
Facts.data.toJSON(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue