UNPKG

xmppjs-chat-bot

Version:
44 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandlerCommand = void 0; const abstract_1 = require("../abstract"); class HandlerCommand extends abstract_1.Handler { constructor(id, room, options) { super(id, room, options); this.commandNames ?? (this.commandNames = []); this.roomCommand = (command, parameters, stanza, fromUser) => { if (!stanza.from) { return; } if (!this.commandNames.includes(command)) { return; } this.handleCommand(command, parameters, stanza, fromUser); }; } loadOptions(options) { if (typeof options !== 'object') { return; } if ('command' in options) { this.commandNames = []; let newcommandNames = options.command; if (!Array.isArray(newcommandNames)) { newcommandNames = [newcommandNames]; } for (const q of newcommandNames) { if (typeof q === 'string') { this.commandNames.push(q); } } } } start() { this.room.on('room_command', this.roomCommand); } stop() { this.room.off('room_command', this.roomCommand); } } exports.HandlerCommand = HandlerCommand; //# sourceMappingURL=abstract.js.map