UNPKG

umbot

Version:

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

106 lines (105 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Card = void 0; const button_1 = require("../button"); const Image_1 = require("../image/Image"); const mmApp_1 = require("../../mmApp"); const AlisaCard_1 = require("./types/AlisaCard"); const TelegramCard_1 = require("./types/TelegramCard"); const VkCard_1 = require("./types/VkCard"); const ViberCard_1 = require("./types/ViberCard"); const MarusiaCard_1 = require("./types/MarusiaCard"); const SmartAppCard_1 = require("./types/SmartAppCard"); class Card { title; desc; images; button; isOne; isUsedGallery = false; template = null; constructor() { this.isOne = false; this.button = new button_1.Buttons(); this.images = []; this.title = null; this.desc = null; this.clear(); } setTitle(title) { this.title = title; return this; } setDescription(description) { this.desc = description; return this; } addButton(button) { if (typeof button === 'string') { this.button.addBtn(button); } else { const title = button.title || button.text || null; const url = button.url || null; const payload = button.payload || null; this.button.addBtn(title, url, payload); } return this; } clear() { this.images = []; } add(image, title, desc = ' ', button = null) { const imageLength = this.images.length; this.addImage(image, title, desc, button); return imageLength < this.images.length; } addImage(image, title, desc = ' ', button = null) { const img = new Image_1.Image(); if (img.init(image, title, desc, button)) { this.images.push(img); } return this; } async getCards(userCard = null) { if (this.template) { return this.template; } let card = null; switch (mmApp_1.mmApp.appType) { case mmApp_1.T_ALISA: card = new AlisaCard_1.AlisaCard(); break; case mmApp_1.T_VK: card = new VkCard_1.VkCard(); break; case mmApp_1.T_TELEGRAM: card = new TelegramCard_1.TelegramCard(); break; case mmApp_1.T_VIBER: card = new ViberCard_1.ViberCard(); break; case mmApp_1.T_MARUSIA: card = new MarusiaCard_1.MarusiaCard(); break; case mmApp_1.T_SMARTAPP: card = new SmartAppCard_1.SmartAppCard(); break; case mmApp_1.T_USER_APP: card = userCard; break; } if (card) { card.isUsedGallery = this.isUsedGallery; card.images = this.images; card.button = this.button; card.title = this.title; return await card.getCard(this.isOne); } return {}; } async getCardsJson(userCard = null) { return JSON.stringify(await this.getCards(userCard)); } } exports.Card = Card;