UNPKG

pockybot

Version:

Spark bot that handles team recognition

37 lines (36 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const trigger_1 = require("../../models/trigger"); const constants_1 = require("../../constants"); const logger_1 = require("../logger"); const database_1 = require("../../models/database"); const command_1 = require("../../models/command"); const xmlMessageParser_1 = require("../parsers/xmlMessageParser"); class Results extends trigger_1.default { constructor(resultsService, config) { super(); this.cannotDisplayResults = 'Error encountered; cannot display results.'; this.resultsService = resultsService; this.config = config; } isToTriggerOn(message) { if (!(this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Results))) { return false; } let parsedMessage = xmlMessageParser_1.default.parseNonPegMessage(message); return parsedMessage.botId === constants_1.default.botId && parsedMessage.command.toLowerCase() === command_1.Command.Results; } async createMessage() { try { let response = await this.resultsService.returnResultsMarkdown(); return { markdown: response }; } catch (error) { logger_1.Logger.error(`[Results.createMessage] Error obtaining results: ${error.message}`); throw new Error(this.cannotDisplayResults); } } } exports.default = Results;