smartuniverse/dist_ts/smartuniverse.classes.reactionresponse.js

49 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

2020-09-24 18:13:48 +00:00
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactionResponse = void 0;
const plugins = __importStar(require("./smartuniverse.plugins"));
class ReactionResponse {
constructor(optionsArg) {
this.channels = new plugins.lik.ObjectMap();
this.method = optionsArg.method;
this.channels.addArray(optionsArg.channels);
this.funcDef = optionsArg.funcDef;
for (const channel of this.channels.getArray()) {
channel.subscribe(messageArg => {
this.processMessageForReaction(channel, messageArg);
});
}
}
async processMessageForReaction(channelArg, messageArg) {
if (messageArg.messageText === 'reactionRequest' &&
messageArg.payload.typedRequestPayload.method === this.method) {
const response = await this.funcDef(messageArg.payload.typedRequestPayload.request);
const payload = Object.assign(Object.assign({}, messageArg.payload), { typedRequestPayload: Object.assign(Object.assign({}, messageArg.payload.typedRequestPayload), { response }) });
channelArg.sendMessage({
messageText: 'reactionResponse',
payload
});
}
}
}
exports.ReactionResponse = ReactionResponse;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnJlYWN0aW9ucmVzcG9uc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmN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