xmppjs-chat-bot
Version:
Server-side XMPP chat bot
41 lines • 1.53 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.HandlerCommandSay = void 0;
const abstract_1 = require("./abstract");
const handlers_directory_1 = require("../../handlers_directory");
class HandlerCommandSay extends abstract_1.HandlerCommand {
constructor(id, room, options) {
super(id, room, options);
this.quotes ?? (this.quotes = []);
}
loadOptions(options) {
super.loadOptions(options);
if (typeof options !== 'object') {
return;
}
if ('quotes' in options) {
this.quotes = [];
let newQuotes = options.quotes;
if (!Array.isArray(newQuotes)) {
newQuotes = [newQuotes];
}
for (const q of newQuotes) {
if (typeof q === 'string') {
this.quotes.push(q);
}
}
}
}
handleCommand(command, _parameters, _stanza, _user) {
let count = Math.round(Math.random() * (this.quotes.length - 1));
if (count >= this.quotes.length) {
count = 0;
}
this.logger.info(`Emitting the message number ${count}, responding to !${command}.`);
const txt = this.quotes[count];
this.room.sendGroupchat(txt).catch((err) => { this.logger.error(err); });
}
}
exports.HandlerCommandSay = HandlerCommandSay;
handlers_directory_1.HandlersDirectory.singleton().register('command_say', HandlerCommandSay);
//# sourceMappingURL=say.js.map
;