2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 13:47:54 +00:00

delete /groups and /link responses after 5 min

This commit is contained in:
Pouria Ezzati 2017-10-02 12:35:40 +03:30
parent 1f693bf3d0
commit 1b12efce72
2 changed files with 19 additions and 7 deletions

View File

@ -3,6 +3,9 @@
// Utils
const { escapeHtml } = require('../../utils/tg');
// Bot
const bot = require('../../bot');
// DB
const { listGroups } = require('../../stores/group');
@ -16,19 +19,23 @@ const entry = group => group.username
? `- @${group.username}`
: `- <a href="${group.link}">${escapeHtml(group.title)}</a>`;
const groupsHandler = async ctx => {
const groupsHandler = async ({ chat, replyWithHTML }) => {
if (config.groupsString) {
return ctx.replyWithHTML(config.groupsString);
return replyWithHTML(config.groupsString);
}
const groups = await listGroups();
const entries = groups.map(entry).join('\n');
return ctx.replyWithHTML(`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
disable_web_page_preview: true,
reply_markup,
});
const { message_id } = await replyWithHTML(
`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
disable_web_page_preview: true,
reply_markup,
});
return setTimeout(() =>
bot.telegram.deleteMessage(chat.id, message_id), 5 * 60 * 1000);
};

View File

@ -1,15 +1,20 @@
'use strict';
// Bot
const bot = require('../../bot');
// DB
const { managesGroup } = require('../../stores/group');
const linkHandler = async ({ chat, replyWithHTML }) => {
const group = await managesGroup(chat);
return replyWithHTML(
const { message_id } = await replyWithHTML(
' <b>Group\'s link:</b>\n\n' +
`<a href="${group.link}">${group.title}</a>`
);
return setTimeout(() =>
bot.telegram.deleteMessage(chat.id, message_id), 5 * 60 * 1000);
};
module.exports = linkHandler;