2017-07-24 17:12:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-10-31 22:20:49 +01:00
|
|
|
const { telegram } = require('../bot');
|
|
|
|
|
2018-05-20 12:07:12 +02:00
|
|
|
const R = require('ramda');
|
|
|
|
|
|
|
|
const isCommand = R.pipe(
|
|
|
|
R.defaultTo({}),
|
|
|
|
R.path([ 'entities', 0 ]),
|
|
|
|
R.defaultTo({}),
|
|
|
|
R.whereEq({ offset: 0, type: 'bot_command' }),
|
|
|
|
);
|
|
|
|
|
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-11-24 15:20:08 +01:00
|
|
|
const deleteAfter = ms => (ctx, next) => {
|
|
|
|
setTimeout(ctx.deleteMessage, ms);
|
|
|
|
next();
|
|
|
|
};
|
2017-07-24 18:08:31 +02:00
|
|
|
|
2017-11-01 21:45:59 +01:00
|
|
|
const scheduleDeletion = ({ chat, message_id }) => {
|
2017-10-31 22:20:49 +01:00
|
|
|
if (chat.type === 'private') {
|
|
|
|
return null;
|
|
|
|
}
|
2017-11-01 21:45:59 +01:00
|
|
|
return setTimeout(
|
|
|
|
() => telegram.deleteMessage(chat.id, message_id),
|
|
|
|
5 * 60 * 1000
|
|
|
|
);
|
2017-10-31 22:20:49 +01:00
|
|
|
};
|
|
|
|
|
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,
|
2018-05-20 12:07:12 +02:00
|
|
|
isCommand,
|
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
|
|
|
};
|