@globalart/nestcord
Version:
A module for creating Discord bots using NestJS, based on Discord.js
90 lines (89 loc) • 4.64 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandsModule = void 0;
const common_1 = require("@nestjs/common");
const context_menus_1 = require("./context-menus");
const slash_commands_1 = require("./slash-commands");
const commands_service_1 = require("./commands.service");
const discord_js_1 = require("discord.js");
const nestcord_module_definition_1 = require("../nestcord.module-definition");
let CommandsModule = class CommandsModule {
constructor(client, options, commandsService, contextMenusService, slashCommandsService) {
this.client = client;
this.options = options;
this.commandsService = commandsService;
this.contextMenusService = contextMenusService;
this.slashCommandsService = slashCommandsService;
}
onModuleInit() {
return __awaiter(this, void 0, void 0, function* () {
this.client.once('ready', () => __awaiter(this, void 0, void 0, function* () {
yield this.initializeClient();
}));
});
}
initializeClient() {
return __awaiter(this, void 0, void 0, function* () {
const { skipGetCommandInfoFromDiscord, skipRegistration } = this.options;
if (!skipGetCommandInfoFromDiscord) {
yield this.client.application.commands.fetch();
this.commandsService.getAllCommandsAndSetDiscordResponseMeta();
}
if (!skipRegistration) {
if (this.client.application.partial) {
yield this.client.application.fetch();
}
yield this.commandsService.registerAllCommands();
if (!skipGetCommandInfoFromDiscord) {
this.commandsService.getAllCommandsAndSetDiscordResponseMeta();
}
}
});
}
onApplicationBootstrap() {
const commands = [
...this.contextMenusService.cache.values(),
...this.slashCommandsService.cache.values(),
];
commands.forEach((command) => {
const guilds = Array.isArray(this.options.development)
? this.options.development
: command.getGuilds() || [undefined];
command.setGuilds(guilds);
});
}
};
exports.CommandsModule = CommandsModule;
exports.CommandsModule = CommandsModule = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({
imports: [context_menus_1.ContextMenusModule, slash_commands_1.SlashCommandsModule],
providers: [commands_service_1.CommandsService],
exports: [context_menus_1.ContextMenusModule, slash_commands_1.SlashCommandsModule, commands_service_1.CommandsService],
}),
__param(1, (0, common_1.Inject)(nestcord_module_definition_1.NESTCORD_MODULE_OPTIONS)),
__metadata("design:paramtypes", [discord_js_1.Client, Object, commands_service_1.CommandsService,
context_menus_1.ContextMenusService,
slash_commands_1.SlashCommandsService])
], CommandsModule);