2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-25 11:27:20 +00:00

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-09-24 23:23:36 +02:00
'use strict';
const XRegExp = require('xregexp');
2017-09-24 23:23:36 +02:00
// Utils
const { escapeHtml, scheduleDeletion } = require('../../utils/tg');
2017-09-24 23:23:36 +02:00
// DB
const { listVisibleGroups } = require('../../stores/group');
2017-09-24 23:23:36 +02:00
const config = require('../../config');
2017-09-24 23:23:36 +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
const emojiRegex = XRegExp.tag('gx')`
[\uE000-\uF8FF]|
\uD83C[\uDC00-\uDFFF]|
\uD83D[\uDC00-\uDFFF]|
[\u2011-\u26FF]|
\uD83E[\uDD10-\uDDFF]`;
const stripEmoji = s => s.replace(emojiRegex, '');
const groupsHandler = async ({ 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 listVisibleGroups();
2017-09-24 23:23:36 +02: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');
return replyWithHTML(`🛠 <b>Groups I manage</b>:\n\n${entries}`, {
disable_web_page_preview: true,
reply_markup,
}).then(scheduleDeletion());
2017-09-24 23:23:36 +02:00
};
module.exports = groupsHandler;