@kaufman-bot/jokes-generator-server
Version:
Command to generate text with a random jokes
63 lines • 2.8 kB
JavaScript
;
var RuJokesGeneratorService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuJokesGeneratorService = 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 RUSSIAN_LANGUAGE = 'ru';
let RuJokesGeneratorService = RuJokesGeneratorService_1 = class RuJokesGeneratorService {
constructor(scraperService, botCommandsToolsService) {
this.scraperService = scraperService;
this.botCommandsToolsService = botCommandsToolsService;
this.handlerId = RuJokesGeneratorService_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(RUSSIAN_LANGUAGE)) {
return null;
}
return yield this.scraperService.onHelp(msg, ctx, RuJokesGeneratorService_1.name);
});
}
onMessage(msg, ctx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!msg.locale.includes(RUSSIAN_LANGUAGE)) {
return null;
}
if (this.botCommandsToolsService.checkCommands(msg.text, [...Object.keys(core_server_1.BotCommandsEnum)], msg.locale)) {
const result = yield this.scraperService.onMessage(msg, ctx, RuJokesGeneratorService_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;
});
}
};
RuJokesGeneratorService = RuJokesGeneratorService_1 = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__metadata("design:paramtypes", [html_scraper_server_1.ScraperService,
core_server_1.BotCommandsToolsService])
], RuJokesGeneratorService);
exports.RuJokesGeneratorService = RuJokesGeneratorService;
//# sourceMappingURL=ru-jokes-generator.service.js.map