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');
|
|
|
|
|
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*\?*
|
|
|
|
$`;
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-04 14:06:24 +02:00
|
|
|
const $regex = XRegExp.tag('ni')`^(the\s)?${groupName}(\sgroup|\schat)?$`;
|
2018-01-30 14:38:50 +01:00
|
|
|
|
|
|
|
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);
|