2017-09-24 23:23:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Utils
|
2017-10-31 22:20:49 +01:00
|
|
|
const { escapeHtml, scheduleDeletion } = require('../../utils/tg');
|
2017-10-02 12:35:40 +03:30
|
|
|
|
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');
|
|
|
|
|
2017-09-25 15:38:03 +02:00
|
|
|
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
|
|
|
|
2017-10-31 22:20:49 +01:00
|
|
|
const groupsHandler = async ({ replyWithHTML }) => {
|
2017-09-24 23:23:36 +02:00
|
|
|
if (config.groupsString) {
|
2017-10-02 12:35:40 +03:30
|
|
|
return replyWithHTML(config.groupsString);
|
2017-09-24 23:23:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const groups = await listGroups();
|
|
|
|
|
|
|
|
const entries = groups.map(entry).join('\n');
|
|
|
|
|
2017-10-31 22:20:49 +01:00
|
|
|
return replyWithHTML(
|
2017-10-02 12:35:40 +03:30
|
|
|
`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
|
|
|
|
disable_web_page_preview: true,
|
|
|
|
reply_markup,
|
2017-10-31 22:20:49 +01:00
|
|
|
}).then(scheduleDeletion);
|
2017-09-24 23:23:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = groupsHandler;
|