@kaufman-bot/facts-generator-server
Version:
Command to generate text with a random fact
70 lines • 3.17 kB
JavaScript
;
var FactsGeneratorService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FactsGeneratorService = void 0;
const tslib_1 = require("tslib");
const core_server_1 = require("@kaufman-bot/core-server");
const html_scraper_server_1 = require("@kaufman-bot/html-scraper-server");
const common_1 = require("@nestjs/common");
const nestjs_translates_1 = require("nestjs-translates");
let FactsGeneratorService = FactsGeneratorService_1 = class FactsGeneratorService {
constructor(scraperService, translatesStorage, botCommandsToolsService) {
this.scraperService = scraperService;
this.translatesStorage = translatesStorage;
this.botCommandsToolsService = botCommandsToolsService;
this.handlerId = FactsGeneratorService_1.name;
}
onContextBotCommands(msg, ctx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const contextMsg = yield this.scraperService.onContextBotCommands(msg);
return contextMsg ? this.onMessage(contextMsg.message, ctx) : null;
});
}
onHelp(msg, ctx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!msg.locale.includes(this.translatesStorage.defaultLocale)) {
return null;
}
return yield this.scraperService.onHelp(msg, ctx, FactsGeneratorService_1.name);
});
}
onMessage(msg, ctx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!msg.locale.includes(this.translatesStorage.defaultLocale)) {
return null;
}
if (this.botCommandsToolsService.checkCommands(msg.text, [...Object.keys(core_server_1.BotCommandsEnum)], msg.locale)) {
const result = yield this.scraperService.onMessage(msg, ctx, FactsGeneratorService_1.name);
try {
if ((result === null || result === void 0 ? void 0 : result.type) === 'text') {
return {
type: 'text',
message: msg,
text: result.text
.replace('\n\nTweet [http://twitter.com/share]', '')
.split('\\"')
.join('"')
.split('\n')
.join(' '),
};
}
return result;
}
catch (err) {
console.debug(result);
console.error(err, err.stack);
throw err;
}
}
return null;
});
}
};
FactsGeneratorService = FactsGeneratorService_1 = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__metadata("design:paramtypes", [html_scraper_server_1.ScraperService,
nestjs_translates_1.TranslatesStorage,
core_server_1.BotCommandsToolsService])
], FactsGeneratorService);
exports.FactsGeneratorService = FactsGeneratorService;
//# sourceMappingURL=facts-generator.service.js.map