2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 19:07:17 +00:00

48 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2020-05-13 22:35:50 +02:00
// @ts-check
2017-09-24 23:23:36 +02:00
'use strict';
const XRegExp = require('xregexp');
2017-09-24 23:23:36 +02:00
// Utils
2020-05-13 22:35:50 +02:00
const { scheduleDeletion } = require('../../utils/tg');
const { TgHtml } = require('../../utils/html');
2017-09-24 23:23:36 +02:00
// DB
const { listVisibleGroups } = require('../../stores/group');
2017-09-24 23:23:36 +02:00
2020-03-09 23:27:19 +01:00
const { config } = require('../../utils/config');
2017-09-24 23:23:36 +02:00
const inline_keyboard = config.groupsInlineKeyboard;
2020-05-13 22:35:50 +02:00
const reply_markup = inline_keyboard && { inline_keyboard };
2017-09-25 16:14:29 +03:30
const entry = group => group.username
? `- @${group.username}`
2020-05-13 22:35:50 +02:00
: TgHtml.tag`- <a href="${group.link}">${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, '');
2020-03-10 22:10:48 +01:00
/** @param { import('../../typings/context').ExtendedContext } ctx */
2021-05-07 22:46:11 +02:00
const groupsHandler = async (ctx) => {
const groups = await listVisibleGroups();
2017-09-24 23:23:36 +02:00
groups.sort((a, b) =>
stripEmoji(a.title).localeCompare(stripEmoji(b.title)));
2020-05-13 22:35:50 +02:00
const entries = TgHtml.join('\n', groups.map(entry));
2017-09-24 23:23:36 +02:00
2021-05-07 22:46:11 +02:00
return ctx.replyWithHTML(TgHtml.tag`🛠 <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;