mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-30 21:55:17 +00:00
Invite link checking based on chat ID rather than known invite links
This commit is contained in:
committed by
Wojciech Pawlik
parent
959bef339d
commit
b271c53fd8
@@ -7,6 +7,7 @@ const { URL } = require('url');
|
|||||||
const { taggedSum } = require('daggy');
|
const { taggedSum } = require('daggy');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const R = require('ramda');
|
const R = require('ramda');
|
||||||
|
const { jspack } = require('jspack');
|
||||||
|
|
||||||
const { isAdmin } = require('../../stores/user');
|
const { isAdmin } = require('../../stores/user');
|
||||||
const { managesGroup } = require('../../stores/group');
|
const { managesGroup } = require('../../stores/group');
|
||||||
@@ -84,6 +85,26 @@ const isPublic = async username => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const inviteLinkToGroupID = url => {
|
||||||
|
if (url.pathname.toLowerCase().startsWith('/joinchat/')) {
|
||||||
|
const [ , groupID ] =
|
||||||
|
jspack.Unpack(
|
||||||
|
'>LLC',
|
||||||
|
Buffer.from(url.pathname.split('/')[2], 'base64'),
|
||||||
|
);
|
||||||
|
return groupID;
|
||||||
|
}
|
||||||
|
throw new Error(`${url.toString()} is not an invite link`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const inviteLinkIsManagedGroup = link => {
|
||||||
|
try {
|
||||||
|
return managesGroup({ id: inviteLinkToGroupID(link) });
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const dh = {
|
const dh = {
|
||||||
blacklistedDomain: R.always(Action.Warn('Link to a blacklisted domain')),
|
blacklistedDomain: R.always(Action.Warn('Link to a blacklisted domain')),
|
||||||
nothing: R.always(Action.Nothing),
|
nothing: R.always(Action.Nothing),
|
||||||
@@ -94,7 +115,7 @@ const dh = {
|
|||||||
return Action.Nothing;
|
return Action.Nothing;
|
||||||
}
|
}
|
||||||
if (url.searchParams.has('start')) return Action.Warn('Bot reflink');
|
if (url.searchParams.has('start')) return Action.Warn('Bot reflink');
|
||||||
if (await managesGroup({ link: url.toString() })) return Action.Nothing;
|
if (await inviteLinkIsManagedGroup(url)) return Action.Nothing;
|
||||||
const [ , username ] = R.match(/^\/(\w+)(?:\/\d*)?$/, url.pathname);
|
const [ , username ] = R.match(/^\/(\w+)(?:\/\d*)?$/, url.pathname);
|
||||||
if (username && !await isPublic('@' + username)) return Action.Nothing;
|
if (username && !await isPublic('@' + username)) return Action.Nothing;
|
||||||
return Action.Warn('Link to a Telegram group or channel');
|
return Action.Warn('Link to a Telegram group or channel');
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"daggy": "^1.3.0",
|
"daggy": "^1.3.0",
|
||||||
"dedent-js": "^1.0.1",
|
"dedent-js": "^1.0.1",
|
||||||
|
"jspack": "0.0.4",
|
||||||
"millisecond": "^0.1.2",
|
"millisecond": "^0.1.2",
|
||||||
"nedb-promise": "^2.0.1",
|
"nedb-promise": "^2.0.1",
|
||||||
"node-fetch": "^2.2.0",
|
"node-fetch": "^2.2.0",
|
||||||
|
Reference in New Issue
Block a user