|
| 1 | +import path from "node:path"; |
| 2 | +import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js"; |
| 3 | +import { QuickDB } from "quick.db"; |
| 4 | +import translations from "../../../locales/commands/translations.js"; |
| 5 | +import defaults from "../../util/defaults.js"; |
| 6 | +import __ from "../../service/i18n.js"; |
| 7 | + |
| 8 | +// ========================= // |
| 9 | +// = Copyright (c) NullDev = // |
| 10 | +// ========================= // |
| 11 | + |
| 12 | +const db = new QuickDB({ |
| 13 | + filePath: path.resolve("./data/guild_data.sqlite"), |
| 14 | +}); |
| 15 | + |
| 16 | +const commandName = import.meta.url.split("/").pop()?.split(".").shift() ?? ""; |
| 17 | + |
| 18 | +export default { |
| 19 | + data: new SlashCommandBuilder() |
| 20 | + .setName(commandName) |
| 21 | + .setDescription(translations.set_loser_role.desc) |
| 22 | + .setDescriptionLocalizations(translations.set_loser_role.translations) |
| 23 | + .setDMPermission(false) |
| 24 | + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) |
| 25 | + .addRoleOption((option) => |
| 26 | + option.setName("role") |
| 27 | + .setDescription(translations.set_loser_role.options.role.desc) |
| 28 | + .setDescriptionLocalizations(translations.set_loser_role.options.role.translations) |
| 29 | + .setRequired(true)) |
| 30 | + .addIntegerOption((option) => |
| 31 | + option.setName("duration") |
| 32 | + .setDescription(translations.set_loser_role.options.duration.desc) |
| 33 | + .setDescriptionLocalizations(translations.set_loser_role.options.duration.translations) |
| 34 | + .setRequired(true)), |
| 35 | + |
| 36 | + /** |
| 37 | + * @param {import("discord.js").CommandInteraction} interaction |
| 38 | + */ |
| 39 | + async execute(interaction){ |
| 40 | + const role = interaction.options.get("role")?.value; |
| 41 | + const duration = interaction.options.get("duration")?.value || defaults.loser_role_duration; |
| 42 | + |
| 43 | + if (!role || !duration){ |
| 44 | + return await interaction.reply({ |
| 45 | + content: await __("errors.invalid_argument")(interaction.guildId), |
| 46 | + ephemeral: true, |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + await db.set(`guild-${interaction.guildId}.loserRole`, role); |
| 51 | + await db.set(`guild-${interaction.guildId}.loserRoleDuration`, duration); |
| 52 | + |
| 53 | + const rolename = (await interaction.guild?.roles.fetch(String(role))?.catch(() => null))?.name; |
| 54 | + |
| 55 | + return await interaction.reply({ |
| 56 | + content: await __("replies.set_loser_role", rolename, duration)(interaction.guildId), |
| 57 | + ephemeral: true, |
| 58 | + }); |
| 59 | + }, |
| 60 | +}; |
0 commit comments