UNPKG

stalkee

Version:

a Telegram bot who can send voice messages via inline mode added by admin with sorting them by numbers of uses

31 lines (30 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.inlineQuery = void 0; const uuid_1 = require("uuid"); const utils_1 = require("../../utils"); const controllers_1 = require("../../controllers"); const audioToQueryResult = (audio) => { return { type: 'document', id: `${audio.fileUid}.${(0, uuid_1.v4)()}`, title: audio.quote, description: `${audio.actor || ''}${audio.location ? ' ◆︎ ' + audio.location : ''}\n▷ ${audio.nUses}`, document_file_id: audio.fileId }; }; const inlineQuery = async (ctx) => { try { const query = ctx.inlineQuery?.query.trim().split(/\s+/g).join(' '); if (query == null) { return await ctx.answerInlineQuery([], { cache_time: 30 }); } const audios = await (0, controllers_1.selectAudios)(query); await ctx.answerInlineQuery(audios.length > 0 ? audios.map(audioToQueryResult) : [], { cache_time: 30 }); } catch (err) { utils_1.logger.error('' + err, 'handler.inline_query'); await ctx.answerInlineQuery([], { cache_time: 0 }); } }; exports.inlineQuery = inlineQuery;