2017-07-24 17:12:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-10-31 22:20:49 +01:00
|
|
|
const { telegram } = require('../bot');
|
|
|
|
|
|
|
|
const { promisify } = require('util');
|
|
|
|
|
|
|
|
const delay = promisify(setTimeout);
|
|
|
|
|
2017-09-24 14:55:26 +02:00
|
|
|
const escapeHtml = s => s
|
|
|
|
.replace(/</g, '<');
|
|
|
|
|
|
|
|
const link = ({ id, first_name }) =>
|
|
|
|
`<a href="tg://user?id=${id}">${escapeHtml(first_name)}</a>`;
|
2017-07-24 17:12:38 +02:00
|
|
|
|
2017-10-22 17:33:21 +02:00
|
|
|
const quietLink = (user) =>
|
|
|
|
user.username
|
|
|
|
? `<a href="t.me/${user.username}">${escapeHtml(user.first_name)}</a>`
|
|
|
|
: link(user);
|
|
|
|
|
2017-10-04 23:57:47 +05:30
|
|
|
/**
|
|
|
|
* @param {number} ms
|
|
|
|
* Deletes messages after (ms) milliseconds
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
2017-07-24 18:08:31 +02:00
|
|
|
const deleteAfter = ms => ctx =>
|
2017-10-31 23:08:22 +01:00
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
ctx.telegram.deleteMessage(ctx.chat.id, ctx.message.message_id),
|
|
|
|
ms
|
|
|
|
);
|
2017-07-24 18:08:31 +02:00
|
|
|
|
2017-10-31 22:20:49 +01:00
|
|
|
const scheduleDeletion = async ({ chat, message_id }) => {
|
|
|
|
if (chat.type === 'private') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
await delay(5 * 60 * 1000);
|
|
|
|
return telegram.deleteMessage(chat.id, message_id);
|
|
|
|
};
|
|
|
|
|
2017-07-24 17:12:38 +02:00
|
|
|
module.exports = {
|
2017-07-24 18:08:31 +02:00
|
|
|
deleteAfter,
|
2017-09-24 23:23:13 +02:00
|
|
|
escapeHtml,
|
2017-10-22 17:33:21 +02:00
|
|
|
link,
|
|
|
|
quietLink,
|
2017-10-31 22:20:49 +01:00
|
|
|
scheduleDeletion,
|
2017-07-24 17:12:38 +02:00
|
|
|
};
|