@globalart/nestcord
Version:
A module for creating Discord bots using NestJS, based on Discord.js
44 lines (43 loc) • 1.66 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 ModalsService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModalsService = void 0;
const common_1 = require("@nestjs/common");
const discord_js_1 = require("discord.js");
/**
* Service that manages modals.
*/
let ModalsService = ModalsService_1 = class ModalsService {
constructor() {
this.logger = new common_1.Logger(ModalsService_1.name);
this.cache = new discord_js_1.Collection();
}
add(modal) {
const id = modal.getCustomId();
if (this.cache.has(id)) {
this.logger.warn(`Modal : ${id} already exists`);
}
this.cache.set(id, modal);
}
get(customId) {
for (const modal of this.cache.values()) {
if (modal.matcher(customId)) {
return modal;
}
}
return null;
}
remove(customId) {
this.cache.delete(customId);
}
};
exports.ModalsService = ModalsService;
exports.ModalsService = ModalsService = ModalsService_1 = __decorate([
(0, common_1.Injectable)()
], ModalsService);