pockybot
Version:
Spark bot that handles team recognition
38 lines (37 loc) • 1.54 kB
JavaScript
;
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(winnersService, config) {
super();
this.cannotDisplayResults = 'Error encountered; cannot display winners.';
this.winnersService = winnersService;
this.config = config;
}
isToTriggerOn(message) {
if (!(this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Winners))) {
return false;
}
let parsedMessage = xmlMessageParser_1.default.parseNonPegMessage(message);
return parsedMessage.botId === constants_1.default.botId && parsedMessage.command.toLowerCase() === command_1.Command.Winners;
}
async createMessage() {
let response;
try {
response = await this.winnersService.returnWinnersResponse();
}
catch (error) {
logger_1.Logger.error(`[Winners.createMessage] Error retrieving winners response: ${error.message}`);
throw new Error(this.cannotDisplayResults);
}
return {
markdown: response
};
}
}
exports.default = Results;