Skip to content

Commit 1b12efc

Browse files
committed
delete /groups and /link responses after 5 min
1 parent 1f693bf commit 1b12efc

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

handlers/commands/groups.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// Utils
44
const { escapeHtml } = require('../../utils/tg');
55

6+
// Bot
7+
const bot = require('../../bot');
8+
69
// DB
710
const { listGroups } = require('../../stores/group');
811

@@ -16,19 +19,23 @@ const entry = group => group.username
1619
? `- @${group.username}`
1720
: `- <a href="${group.link}">${escapeHtml(group.title)}</a>`;
1821

19-
const groupsHandler = async ctx => {
22+
const groupsHandler = async ({ chat, replyWithHTML }) => {
2023
if (config.groupsString) {
21-
return ctx.replyWithHTML(config.groupsString);
24+
return replyWithHTML(config.groupsString);
2225
}
2326

2427
const groups = await listGroups();
2528

2629
const entries = groups.map(entry).join('\n');
2730

28-
return ctx.replyWithHTML(`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
29-
disable_web_page_preview: true,
30-
reply_markup,
31-
});
31+
const { message_id } = await replyWithHTML(
32+
`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
33+
disable_web_page_preview: true,
34+
reply_markup,
35+
});
36+
37+
return setTimeout(() =>
38+
bot.telegram.deleteMessage(chat.id, message_id), 5 * 60 * 1000);
3239

3340
};
3441

handlers/commands/link.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use strict';
22

3+
// Bot
4+
const bot = require('../../bot');
5+
36
// DB
47
const { managesGroup } = require('../../stores/group');
58

69
const linkHandler = async ({ chat, replyWithHTML }) => {
710
const group = await managesGroup(chat);
811

9-
return replyWithHTML(
12+
const { message_id } = await replyWithHTML(
1013
'ℹ️ <b>Group\'s link:</b>\n\n' +
1114
`<a href="${group.link}">${group.title}</a>`
1215
);
16+
return setTimeout(() =>
17+
bot.telegram.deleteMessage(chat.id, message_id), 5 * 60 * 1000);
1318
};
1419

1520
module.exports = linkHandler;

0 commit comments

Comments
 (0)