2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 10:28:09 +00:00
Martin f91f6ef4f5
Change deprecated .tg Telegraf alias for .telegram (#152)
* Swap deprecated .tg for .telegram
2022-05-31 17:17:45 +02:00

36 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const R = require('ramda');
const { html } = require('../../utils/html');
const { parse } = require('../../utils/cmd');
const { scheduleDeletion } = require('../../utils/tg');
const link = ({ id, first_name }) =>
html`<a href="tg://user?id=${id}">${first_name}</a>`;
/** @param { import('../../typings/context').ExtendedContext } ctx */
module.exports = async (ctx) => {
if (ctx.from.status !== 'admin') return;
const { flags, reason } = parse(ctx.message);
if (!(flags.has('msg_id') || ctx.message.reply_to_message)) {
// eslint-disable-next-line max-len
await ctx.replyWithHTML(' <b>Reply to a message you\'d like to delete</b>').then(scheduleDeletion());
return;
}
await ctx.telegram.deleteMessage(
flags.get('chat_id') || ctx.chat.id,
flags.get('msg_id') || ctx.message.reply_to_message.message_id,
);
if (reason) {
const id = R.path([ 'message', 'reply_to_message', 'from', 'id' ], ctx);
const emoji = id ? link({ id, first_name: '🗑' }) : '🗑';
await ctx.replyWithHTML(html`${emoji} ${reason}`)
.then(scheduleDeletion());
}
};