// @ts-check 'use strict'; const millisecond = require('millisecond'); const { telegram } = require('../bot'); const { html, lrm } = require('./html'); const R = require('ramda'); const replyId = R.path([ 'reply_to_message', 'message_id' ]); const { isCommand } = require('../utils/cmd'); const inlineKeyboard = (...inline_keyboard) => ({ reply_markup: { inline_keyboard } }); const msgLink = msg => msg.chat.username ? `https://t.me/${msg.chat.username}/${msg.message_id}` : `https://t.me/c/${msg.chat.id.toString().slice(4)}/${msg.message_id}`; const link = ({ id, first_name }) => html`${lrm}${first_name} [${id}]`; const quietLink = (user) => user.username ? html`${user.first_name}` : html`${user.first_name}`; const displayUser = user => user.first_name ? link(user) : html`[${user.id}]`; /** @param {number | string | false} ms */ const deleteAfter = ms => (ctx, next) => { if (ms !== false) { setTimeout(ctx.deleteMessage.bind(ctx), millisecond(ms)); } next(); }; /** @param {number | string | false} ms */ const scheduleDeletion = (ms = 5 * 60 * 1000) => message => { const { chat, message_id } = message; if (chat.type !== 'private' && ms !== false) { message.timeout = setTimeout( () => telegram.deleteMessage(chat.id, message_id), millisecond(ms), ); } return message; }; module.exports = { deleteAfter, displayUser, inlineKeyboard, isCommand, link, msgLink, quietLink, replyId, scheduleDeletion, };