UNPKG

umbot

Version:

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

99 lines (98 loc) 3.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.YandexSoundRequest = void 0; const YandexRequest_1 = require("./YandexRequest"); const mmApp_1 = require("../mmApp"); const Request_1 = require("./request/Request"); class YandexSoundRequest extends YandexRequest_1.YandexRequest { STANDARD_URL = 'https://dialogs.yandex.net/api/v1/'; skillId; constructor(oauth = null, skillId = null) { super(oauth); this.skillId = skillId || mmApp_1.mmApp.params.app_id || null; this._request.url = this.STANDARD_URL; } _getSoundsUrl() { return `${this.STANDARD_URL}skills/${this.skillId}/sounds`; } async checkOutPlace() { this._request.url = this.STANDARD_URL + 'status'; const query = await this.call(); if (query && typeof query.sounds.quota !== 'undefined') { return query.sounds.quota; } this._log('YandexSoundRequest.checkOutPlace() Error: Не удалось проверить занятое место!'); return null; } async downloadSoundFile(soundDir) { if (this.skillId) { this._request.url = this._getSoundsUrl(); this._request.header = Request_1.Request.HEADER_FORM_DATA; this._request.attach = soundDir; const query = await this.call(); if (query && query.sound.id !== 'undefined') { return query.sound; } else { this._log('YandexSoundRequest.downloadSoundFile() Error: Не удалось загрузить изображение по пути: ' + soundDir); } } else { this._log('YandexSoundRequest.downloadSoundFile() Error: Не выбран навык!'); } return null; } async getLoadedSounds() { if (this.skillId) { this._request.url = this._getSoundsUrl(); const query = await this.call(); return query?.sounds || null; } else { this._log('YandexSoundRequest.getLoadedSounds() Error: Не выбран навык!'); } return null; } async deleteSound(soundId) { if (this.skillId) { if (soundId) { this._request.url = `${this._getSoundsUrl()}/${soundId}`; this._request.customRequest = 'DELETE'; const query = await this.call(); if (query && typeof query.result !== 'undefined') { return query.result; } else { this._log('YandexSoundRequest.deleteSound() Error: Не удалось удалить картинку!'); } } else { this._log('YandexSoundRequest.deleteSound() Error: Не выбрано изображение!'); } } else { this._log('YandexSoundRequest.deleteSound() Error: Не выбран навык!'); } return null; } async deleteSounds() { if (this.skillId) { const sounds = await this.getLoadedSounds(); if (sounds) { sounds.forEach((sound) => { this.deleteSound(sound.id); }); return true; } else { this._log('YandexSoundRequest.deleteSounds() Error: Не удалось получить загруженные звуки!'); } } else { this._log('YandexSoundRequest.deleteSounds() Error: Не выбран навык!'); } return false; } } exports.YandexSoundRequest = YandexSoundRequest;