2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 10:28:09 +00:00

68 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-13 22:02:41 +01:00
// @ts-check
2017-07-24 17:12:38 +02:00
'use strict';
const millisecond = require('millisecond');
const { telegram } = require('../bot');
2020-06-15 14:45:55 +02:00
const { html, lrm } = require('./html');
const R = require('ramda');
const replyId = R.path([ 'reply_to_message', 'message_id' ]);
2020-06-06 09:20:15 +02:00
const { isCommand } = require('../utils/cmd');
const inlineKeyboard = (...inline_keyboard) =>
({ reply_markup: { inline_keyboard } });
2019-04-06 15:39:40 +02:00
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}`;
2019-04-06 15:39:40 +02:00
const link = ({ id, first_name }) =>
2020-06-15 14:45:55 +02:00
html`${lrm}<a href="tg://user?id=${id}">${first_name}</a> [<code>${id}</code>]`;
2017-07-24 17:12:38 +02:00
const quietLink = (user) =>
user.username
2020-02-12 17:25:29 +01:00
? html`<a href="t.me/${user.username}">${user.first_name}</a>`
2020-05-18 20:43:28 +02:00
: html`<a href="tg://user?id=${user.id}">${user.first_name}</a>`;
const displayUser = user =>
user.first_name
? link(user)
: html`[<code>${user.id}</code>]`;
2020-03-13 22:02:41 +01:00
/** @param {number | string | false} ms */
const deleteAfter = ms => (ctx, next) => {
2019-07-06 10:10:41 -04:00
if (ms !== false) {
2021-05-07 22:46:11 +02:00
setTimeout(ctx.deleteMessage.bind(ctx), millisecond(ms));
2019-07-06 10:10:41 -04:00
}
next();
};
2017-07-24 18:08:31 +02:00
2020-03-13 22:02:41 +01:00
/** @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;
};
2017-07-24 17:12:38 +02:00
module.exports = {
2017-07-24 18:08:31 +02:00
deleteAfter,
displayUser,
inlineKeyboard,
isCommand,
link,
2019-04-06 15:39:40 +02:00
msgLink,
quietLink,
replyId,
scheduleDeletion,
2017-07-24 17:12:38 +02:00
};