hennus-api
Version:
Esta es una libreria para el bot Hennus
70 lines (69 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.commandsManger = void 0;
const Error_1 = require("../Error");
const v10_1 = require("discord-api-types/v10");
class commandsManger {
constructor(_client) {
this._client = _client;
}
;
async set(commands, guildId) {
if (!Array.isArray(commands))
return undefined;
const data = await this._client.rest.api.put(this.paths(guildId), {
body: commands.map(c => this.format(c)),
});
return data;
}
;
async create(command) {
const cmd = this.format(command);
return await this._client.rest.post("applicationCommands", cmd, this._client.aplicationId);
}
;
async delete(id, guildId) {
return await this._client.rest.api.delete(this.paths(guildId, id));
}
;
format(cmd) {
const regex = RegExp(/[A-Z]/g);
if (regex.test(cmd.name))
throw new Error_1.HennusError(Error_1.errorCodes.CommandNameUpperCase);
if (cmd.name.length <= 0 && cmd.name.length > 32)
throw new Error_1.HennusError(Error_1.errorCodes.InvalidCommandNameLength);
if (cmd.default_member_permissions && Array.isArray(cmd.default_member_permissions))
cmd.default_member_permissions = cmd.default_member_permissions.reduce((a, b) => a | b, 0);
return {
name: cmd.name,
description: cmd?.description,
options: cmd.options ?? [],
type: cmd.type ?? 1,
nsfw: cmd.nsfw ?? false,
name_localizations: cmd.name_localizations,
description_localizations: cmd.description_localizations,
default_permission: cmd.default_permission ?? false,
dm_permission: cmd.dm_permission,
default_member_permissions: cmd.default_member_permissions ? cmd.default_member_permissions.toString() : undefined,
};
}
;
paths(guild_id, id) {
if (id) {
if (guild_id)
return v10_1.Routes.applicationGuildCommand(this._client.aplicationId, guild_id, id);
else
return v10_1.Routes.applicationCommand(this._client.aplicationId, id);
}
else {
if (guild_id)
return v10_1.Routes.applicationGuildCommands(this._client.aplicationId, guild_id);
else
return v10_1.Routes.applicationCommands(this._client.aplicationId);
}
;
}
;
}
exports.commandsManger = commandsManger;
;