2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 19:37:14 +00:00

43 lines
969 B
JavaScript
Raw Normal View History

2017-09-24 23:23:36 +02:00
'use strict';
// Utils
const { escapeHtml } = require('../../utils/tg');
// Bot
const bot = require('../../bot');
2017-09-24 23:23:36 +02:00
// DB
2017-09-25 16:17:18 +03:30
const { listGroups } = require('../../stores/group');
2017-09-24 23:23:36 +02:00
const config = require('../../config.json');
const inline_keyboard = config.groupsInlineKeyboard;
const reply_markup = JSON.stringify({ inline_keyboard });
2017-09-25 16:14:29 +03:30
const entry = group => group.username
? `- @${group.username}`
: `- <a href="${group.link}">${escapeHtml(group.title)}</a>`;
2017-09-24 23:23:36 +02:00
const groupsHandler = async ({ chat, replyWithHTML }) => {
2017-09-24 23:23:36 +02:00
if (config.groupsString) {
return replyWithHTML(config.groupsString);
2017-09-24 23:23:36 +02:00
}
const groups = await listGroups();
const entries = groups.map(entry).join('\n');
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);
2017-09-24 23:23:36 +02:00
};
module.exports = groupsHandler;