mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-30 05:37:59 +00:00
Invite link checking based on chat ID rather than known invite links
This commit is contained in:
parent
959bef339d
commit
b271c53fd8
@ -7,6 +7,7 @@ const { URL } = require('url');
|
||||
const { taggedSum } = require('daggy');
|
||||
const fetch = require('node-fetch');
|
||||
const R = require('ramda');
|
||||
const { jspack } = require('jspack');
|
||||
|
||||
const { isAdmin } = require('../../stores/user');
|
||||
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 = {
|
||||
blacklistedDomain: R.always(Action.Warn('Link to a blacklisted domain')),
|
||||
nothing: R.always(Action.Nothing),
|
||||
@ -94,7 +115,7 @@ const dh = {
|
||||
return Action.Nothing;
|
||||
}
|
||||
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);
|
||||
if (username && !await isPublic('@' + username)) return Action.Nothing;
|
||||
return Action.Warn('Link to a Telegram group or channel');
|
||||
|
@ -32,6 +32,7 @@
|
||||
"dependencies": {
|
||||
"daggy": "^1.3.0",
|
||||
"dedent-js": "^1.0.1",
|
||||
"jspack": "0.0.4",
|
||||
"millisecond": "^0.1.2",
|
||||
"nedb-promise": "^2.0.1",
|
||||
"node-fetch": "^2.2.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user