UNPKG

djsbotbase-test

Version:

Discord.js tabanlı komut ve etkinlik sistemlerine sahip bir bot temeli

80 lines (79 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SlashCommand = void 0; const discord_js_1 = require("discord.js"); const logger_1 = require("../helpers/logger"); class SlashCommand { constructor(data) { Object.defineProperty(this, "data", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.validateConstructorData(data); this.data = data; } validateConstructorData(data) { this.validateSlashCommandData(data); this.validateBooleanOptions(data); this.validateCooldown(data); this.validateRunner(data); } validateSlashCommandData(data) { if (!("slashCommandData" in data) || !data.slashCommandData) { (0, logger_1.error)("Slash command data must be provided."); } if (!(data.slashCommandData instanceof discord_js_1.SlashCommandBuilder) && typeof data.slashCommandData !== "function") { (0, logger_1.error)("Slash command data must be a SlashCommandBuilder instance or a function that returns one."); } } validateBooleanOptions(data) { const booleanFields = ["developerOnly", "maintenance"]; for (const field of booleanFields) { if (field in data && data[field] !== undefined && typeof data[field] !== "boolean") { (0, logger_1.error)(`Slash command '${field}' option must be a boolean.`); } } } validateCooldown(data) { if ("cooldown" in data && data.cooldown !== undefined) { if (typeof data.cooldown !== "number" || !Number.isFinite(data.cooldown) || data.cooldown <= 0) { (0, logger_1.error)("Slash command cooldown must be a positive finite number."); } } } validateRunner(data) { if (!("run" in data) || typeof data.run !== "function") { (0, logger_1.error)("Slash command runner must be a function."); } } convertCommandData() { const { slashCommandData } = this.data; if (typeof slashCommandData === "function") { const commandBuilder = slashCommandData(new discord_js_1.SlashCommandBuilder()); if (!(commandBuilder instanceof discord_js_1.SlashCommandBuilder)) { (0, logger_1.error)("Slash command data function must return a valid SlashCommandBuilder instance."); } return commandBuilder; } return slashCommandData; } get slashCommandData() { return this.data.slashCommandData; } get developerOnly() { return this.data.developerOnly ?? false; } get maintenance() { return this.data.maintenance ?? false; } get cooldown() { return this.data.cooldown ?? -1; } get run() { return this.data.run; } } exports.SlashCommand = SlashCommand;