diff --git a/src/commands/index.ts b/src/commands/index.ts index b7578e5..8934492 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -21,11 +21,13 @@ import * as confessdel from "./confessdel"; import * as confessmod from "./confessmod"; import * as ping from "./ping"; import * as setup from "./setup"; +import * as update from "./update"; export const commands = { confess, confessdel, confessmod, ping, - setup + setup, + update }; diff --git a/src/commands/update.ts b/src/commands/update.ts new file mode 100644 index 0000000..640b86e --- /dev/null +++ b/src/commands/update.ts @@ -0,0 +1,56 @@ +/* + * Confoss: Anonymous confessions for Discord, free as in freedom and price! + * Copyright (C) 2024 powermaker450 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; +import { deployCommands } from "../bot"; +import Logger from "../utils/Logger"; + +const logger = new Logger("(/) update"); +const minutes = 5; +const cooldownList = new Set(); + +export const data = new SlashCommandBuilder() + .setName("update") + .setDescription("Update the bot with new data if available") + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); + +export async function execute(interaction: ChatInputCommandInteraction) { + const { id: guildId, name: guildName } = interaction.guild!; + + if (cooldownList.has(guildId)) { + return interaction.reply({ + content: `You can only run the update command once every ${minutes} minutes.`, + ephemeral: true + }); + } + + deployCommands({ guildId: guildId }); + + cooldownList.add(guildId); + logger.log(`Applied cooldown to "${guildName}"`); + + setTimeout(() => { + cooldownList.delete(guildId); + logger.log(`Removed cooldown from "${guildName}"`); + }, minutes*60*1000); + + return interaction.reply({ + content: "Commands refreshed.", + ephemeral: true + }); +}