2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 10:28:09 +00:00
the-guard-bot/handlers/regex/groupLinker.js

38 lines
914 B
JavaScript
Raw Normal View History

'use strict';
const { hears } = require('telegraf');
const XRegExp = require('xregexp');
const { managesGroup } = require.main.require('./stores/group');
const { replyId } = require('../../utils/tg');
2018-04-15 17:26:39 +02:00
const regex = XRegExp.tag('ix')`^
(?<groupName>.+?)
2018-04-18 21:17:59 +02:00
\s(?:chat|gro?u?p)(?:\slink)?
2018-04-15 19:39:28 +02:00
(?:,?\sple?a?[sz]e?)?
2018-04-15 17:26:39 +02:00
\s*\?*
$`;
2020-03-10 22:10:48 +01:00
/** @param { import('../../typings/context').ExtendedContext } ctx */
const handler = async (ctx, next) => {
let [ , groupName ] = ctx.match;
if (groupName.toLowerCase() === 'this') {
if (!ctx.chat.title) return next();
groupName = ctx.chat.title;
}
const $regex = XRegExp.tag('nix')`(^|/\s?)
(the\s)?${groupName}(\sgroup|\schat)?
($|\s?/)`;
const group = await managesGroup({ title: { $regex } });
const { link } = group || {};
if (!link) return next();
return ctx.reply(link, { reply_to_message_id: replyId(ctx.message) });
};
module.exports = hears(regex, handler);