2018-01-30 14:38:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { hears } = require('telegraf');
|
|
|
|
const XRegExp = require('xregexp');
|
|
|
|
|
|
|
|
const { managesGroup } = require.main.require('./stores/group');
|
|
|
|
|
2020-02-19 14:29:05 +01:00
|
|
|
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*\?*
|
|
|
|
$`;
|
2018-01-30 14:38:50 +01:00
|
|
|
|
2020-03-10 22:10:48 +01:00
|
|
|
/** @param { import('../../typings/context').ExtendedContext } ctx */
|
2018-01-30 14:38:50 +01:00
|
|
|
const handler = async (ctx, next) => {
|
|
|
|
let [ , groupName ] = ctx.match;
|
|
|
|
if (groupName.toLowerCase() === 'this') {
|
|
|
|
if (!ctx.chat.title) return next();
|
|
|
|
groupName = ctx.chat.title;
|
|
|
|
}
|
|
|
|
|
2020-02-19 14:29:05 +01:00
|
|
|
const $regex = XRegExp.tag('nix')`(^|/\s?)
|
|
|
|
(the\s)?${groupName}(\sgroup|\schat)?
|
|
|
|
($|\s?/)`;
|
2018-01-30 14:38:50 +01:00
|
|
|
|
|
|
|
const group = await managesGroup({ title: { $regex } });
|
|
|
|
const { link } = group || {};
|
|
|
|
|
|
|
|
if (!link) return next();
|
|
|
|
|
2020-02-19 14:29:05 +01:00
|
|
|
return ctx.reply(link, { reply_to_message_id: replyId(ctx.message) });
|
2018-01-30 14:38:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = hears(regex, handler);
|