2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 02:17:47 +00:00
the-guard-bot/handlers/regex/groupLinker.js
2018-04-15 17:26:14 +02:00

28 lines
695 B
JavaScript

'use strict';
const { hears } = require('telegraf');
const XRegExp = require('xregexp');
const { managesGroup } = require.main.require('./stores/group');
const regex = /^(?:Link to\s+)?(.+) group(?: link)?\s*\?*$/i;
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);