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

45 lines
1008 B
JavaScript
Raw Normal View History

'use strict';
const { hears } = require('telegraf');
const XRegExp = require('xregexp');
const { managesGroup } = require.main.require('./stores/group');
2018-04-15 17:26:39 +02:00
const regex = XRegExp.tag('ix')`^
2018-04-15 19:39:28 +02:00
(?:ple?a?[sz]e?,?\s)?
(?:(?:Can|Could)\s(?:you\s|(?:some|any)(?:one|body)\s))?
2018-04-15 17:26:39 +02:00
(?:(?:
Any
|Link\sto
|Go\s*to
|Ask\sin
|Move\sthis\sto
|(?:Give|tell|dm|pm|send|share)(?:\sme)?
|(?:Do\swe\shave|Is\sthere)(?:\san?y?)?
)\s+)?
(?<groupName>.+?)
2018-04-18 21:17:59 +02:00
\s(?:chat|gro?u?p)(?:\slink)?
2018-04-15 17:26:39 +02:00
(?:\sexists?)?
2018-04-15 19:39:28 +02:00
(?:,?\sple?a?[sz]e?)?
2018-04-15 17:26:39 +02:00
\s*\?*
$`;
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('i')`^${groupName}$`;
const group = await managesGroup({ title: { $regex } });
const { link } = group || {};
if (!link) return next();
return ctx.reply(link, { reply_to_message_id: ctx.message.message_id });
};
module.exports = hears(regex, handler);