UNPKG

umbot

Version:

Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber

99 lines (98 loc) 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BotTest = void 0; const mmApp_1 = require("../mmApp"); const util_1 = require("../utils/standard/util"); const skillsTemplateConfig_1 = require("../platforms/skillsTemplateConfig"); const Bot_1 = require("./Bot"); class BotTest extends Bot_1.Bot { async test({ isShowResult = false, isShowStorage = false, isShowTime = true, userBotClass = null, userBotConfig = null, } = {}) { let count = 0; let state = {}; do { let query = ''; if (count === 0) { console.log("Для выхода введите 'exit'\n"); query = 'Привет'; } else { query = await (0, util_1.stdin)(); if (query === 'exit') { break; } } if (!this._content) { this.setContent(JSON.stringify(this.getSkillContent(query, count, state, userBotConfig))); } const timeStart = Date.now(); if (typeof this._content === 'string') { this.setContent(JSON.parse(this._content)); } let result = await this.run(userBotClass); if (isShowResult) { console.log(`Результат работы: > \n${JSON.stringify(result)}\n\n`); } if (isShowStorage) { console.log(`Данные в хранилище > \n${JSON.stringify(this._botController.userData)}\n\n`); } switch (mmApp_1.mmApp.appType) { case mmApp_1.T_ALISA: if (result.response.text) { result = result.response.text; } else { result = result.response.tts; } break; default: result = this._botController.text; break; } console.log(`Бот: > ${result}\n`); if (isShowTime) { const endTime = Date.now() - timeStart; console.log(`Время выполнения: ${endTime}\n`); } if (this._botController.isEnd) { break; } console.log('Вы: > '); this._content = null; this._botController.text = this._botController.tts = ''; state = this._botController.userData; count++; } while (true); } getSkillContent(query, count, state, userBotConfig) { let content = {}; const userId = 'user_local_test'; switch (mmApp_1.mmApp.appType) { case mmApp_1.T_ALISA: content = (0, skillsTemplateConfig_1.alisaConfig)(query, userId, count, state); break; case mmApp_1.T_MARUSIA: content = (0, skillsTemplateConfig_1.marusiaConfig)(query, userId, count, state); break; case mmApp_1.T_VK: this._botController.isSend = false; content = (0, skillsTemplateConfig_1.vkConfig)(query, userId, count); break; case mmApp_1.T_TELEGRAM: this._botController.isSend = false; content = (0, skillsTemplateConfig_1.telegramConfig)(query, userId, count); break; case mmApp_1.T_VIBER: this._botController.isSend = false; content = (0, skillsTemplateConfig_1.viberConfig)(query, userId); break; case mmApp_1.T_USER_APP: this._botController.isSend = true; if (userBotConfig) { content = userBotConfig(query, userId, count); } break; } return content; } } exports.BotTest = BotTest;