@kaufman-bot/jokes-generator-server
Version:
Command to generate text with a random jokes
65 lines • 2.95 kB
JavaScript
;
var JokesGeneratorService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JokesGeneratorService = 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 JokesGeneratorService = JokesGeneratorService_1 = class JokesGeneratorService {
constructor(scraperService, translatesStorage, botCommandsToolsService) {
this.scraperService = scraperService;
this.translatesStorage = translatesStorage;
this.botCommandsToolsService = botCommandsToolsService;
this.handlerId = JokesGeneratorService_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, JokesGeneratorService_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, JokesGeneratorService_1.name);
try {
if ((result === null || result === void 0 ? void 0 : result.type) === 'text') {
return {
type: 'text',
message: msg,
text: result.text.split('\\"').join('"').split('\n').join(' '),
};
}
return result;
}
catch (err) {
console.debug(result);
console.error(err, err.stack);
throw err;
}
}
return null;
});
}
};
JokesGeneratorService = JokesGeneratorService_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])
], JokesGeneratorService);
exports.JokesGeneratorService = JokesGeneratorService;
//# sourceMappingURL=jokes-generator.service.js.map