From 096d8fe1ffe74090361f21a0e95149fb65174757 Mon Sep 17 00:00:00 2001 From: Wojciech Pawlik Date: Wed, 12 Feb 2020 17:25:29 +0100 Subject: [PATCH] Improve /del --- README.md | 1 + handlers/commands/commands.js | 1 + handlers/commands/del.js | 13 ++++++++++--- utils/tg.js | 7 ++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 59d98e2..4d49201 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Command | Role | Available at | Description `/leave ` | _Master_ | _Everywhere_ | Make the bot to leave the group cleanly. `/hidegroup` | _Master_ | _Groups_ | Revoke invite link and hide the group from `/groups` list. `/showgroup` | _Master_ | _Groups_ | Make the group accessible via `/groups` list. +`/del [reason]` | _Admin_ | _Everywhere_ | Deletes replied-to message. `/warn ` | _Admin_ | _Groups_ | Warns the user. `/unwarn` | _Admin_ | _Everywhere_ | Removes the last warn from the user. `/nowarns` | _Admin_ | _Everywhere_ | Clears warns for the user. diff --git a/handlers/commands/commands.js b/handlers/commands/commands.js index f3fc69c..21b2d16 100644 --- a/handlers/commands/commands.js +++ b/handlers/commands/commands.js @@ -21,6 +21,7 @@ const masterCommands = `\ const adminCommands = `\ Admin commands: +/del [reason] - Deletes replied-to message. /warn <reason> - Warns the user. /unwarn - Removes the last warn from the user. /nowarns - Clears warns for the user. diff --git a/handlers/commands/del.js b/handlers/commands/del.js index 9a0adad..4b6a544 100644 --- a/handlers/commands/del.js +++ b/handlers/commands/del.js @@ -1,8 +1,10 @@ 'use strict'; -const { parse } = require('../../utils/parse'); +const html = require('tg-html'); +const R = require('ramda'); -const { scheduleDeletion } = require('../../utils/tg'); +const { parse } = require('../../utils/parse'); +const { link, scheduleDeletion } = require('../../utils/tg'); module.exports = async (ctx) => { if (ctx.from.status !== 'admin') return; @@ -21,6 +23,11 @@ module.exports = async (ctx) => { ); if (reason) { - await ctx.reply(`🗑 ${reason}`); + const emoji = link({ + id: R.path([ 'message', 'reply_to_message', 'from', 'id' ], ctx), + first_name: '🗑', + }); + await ctx.replyWithHTML(html`${emoji} ${reason}`) + .then(scheduleDeletion()); } }; diff --git a/utils/tg.js b/utils/tg.js index c04d29c..bfd1fd6 100644 --- a/utils/tg.js +++ b/utils/tg.js @@ -3,6 +3,7 @@ const millisecond = require('millisecond'); const { telegram } = require('../bot'); +const html = require('tg-html'); const R = require('ramda'); const isCommand = R.pipe( @@ -22,17 +23,17 @@ const msgLink = msg => `https://t.me/c/${msg.chat.id.toString().slice(4)}/${msg.message_id}`; const link = ({ id, first_name }) => - `${escapeHtml(first_name)}`; + html`${first_name}`; const quietLink = (user) => user.username - ? `${escapeHtml(user.first_name)}` + ? html`${user.first_name}` : link(user); const displayUser = user => user.first_name ? link(user) - : `an user with id ${user.id}`; + : html`an user with id ${user.id}`; /** * @param {number} ms