2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 18:38:05 +00:00
GingerPlusPlus 642f2e99c3 Use router instead of composer in commands/index
+ Makes commands case-insensitive
+ Avoids hardcoding commands in commands/addCommand
2018-05-20 12:07:12 +02:00

53 lines
1002 B
JavaScript

'use strict';
const { telegram } = require('../bot');
const R = require('ramda');
const isCommand = R.pipe(
R.defaultTo({}),
R.path([ 'entities', 0 ]),
R.defaultTo({}),
R.whereEq({ offset: 0, type: 'bot_command' }),
);
const escapeHtml = s => s
.replace(/</g, '&lt;');
const link = ({ id, first_name }) =>
`<a href="tg://user?id=${id}">${escapeHtml(first_name)}</a>`;
const quietLink = (user) =>
user.username
? `<a href="t.me/${user.username}">${escapeHtml(user.first_name)}</a>`
: link(user);
/**
* @param {number} ms
* Deletes messages after (ms) milliseconds
* @returns {undefined}
*/
const deleteAfter = ms => (ctx, next) => {
setTimeout(ctx.deleteMessage, ms);
next();
};
const scheduleDeletion = ({ chat, message_id }) => {
if (chat.type === 'private') {
return null;
}
return setTimeout(
() => telegram.deleteMessage(chat.id, message_id),
5 * 60 * 1000
);
};
module.exports = {
deleteAfter,
escapeHtml,
isCommand,
link,
quietLink,
scheduleDeletion,
};