2017-09-24 23:23:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2019-02-03 15:33:05 +05:00
|
|
|
const XRegExp = require('xregexp');
|
|
|
|
|
2017-09-24 23:23:36 +02:00
|
|
|
// 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
|
2018-04-03 00:21:00 +02:00
|
|
|
const { listVisibleGroups } = require('../../stores/group');
|
2017-09-24 23:23:36 +02:00
|
|
|
|
2017-11-24 12:31:47 +01:00
|
|
|
const config = require('../../config');
|
2017-09-24 23:23:36 +02:00
|
|
|
|
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
|
|
|
|
2019-02-03 21:16:50 +05:00
|
|
|
const emojiRegex = XRegExp.tag('gx')`
|
2019-02-03 15:33:05 +05:00
|
|
|
[\uE000-\uF8FF]|
|
|
|
|
\uD83C[\uDC00-\uDFFF]|
|
|
|
|
\uD83D[\uDC00-\uDFFF]|
|
|
|
|
[\u2011-\u26FF]|
|
|
|
|
\uD83E[\uDD10-\uDDFF]`;
|
|
|
|
|
|
|
|
const stripEmoji = s => s.replace(emojiRegex, '');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-03 00:21:00 +02:00
|
|
|
const groups = await listVisibleGroups();
|
2017-09-24 23:23:36 +02:00
|
|
|
|
2019-02-03 15:33:05 +05:00
|
|
|
groups.sort((a, b) =>
|
|
|
|
stripEmoji(a.title).localeCompare(stripEmoji(b.title)));
|
|
|
|
|
2017-09-24 23:23:36 +02:00
|
|
|
const entries = groups.map(entry).join('\n');
|
|
|
|
|
2017-10-31 23:08:22 +01:00
|
|
|
return replyWithHTML(`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
|
|
|
|
disable_web_page_preview: true,
|
|
|
|
reply_markup,
|
2018-11-20 11:47:30 +05:30
|
|
|
}).then(scheduleDeletion());
|
2017-09-24 23:23:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = groupsHandler;
|