Updated embed check to include TikTok checks. Consolidated the code and removed unnecessary logic checks.

This commit is contained in:
2026-01-26 21:27:30 -05:00
parent 5c5e2ee5ba
commit 8157ca00a8

View File

@@ -7,6 +7,7 @@ import { urql } from "#root/main.js";
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
import addGroup from "#root/lib/graphql/mutations/addGroupMutation.js";
import incrementGroup from "#root/lib/graphql/mutations/incrementGroupMutation.js";
import tiktokLinkCheck from "#root/lib/tiktokLinkCheck.js";
const composer = new Composer<Context>();
@@ -32,160 +33,68 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
// Filters every message/caption entity that is a url into a new array.
const embeds = ctx.msg.entities
? ctx.msg.entities.filter(e => e.type === "text_link")
: null;
: [];
const captionEmbeds = ctx.msg.caption_entities
? ctx.msg.caption_entities.filter(e => e.type === "text_link")
: null;
: [];
const allEmbeds = embeds.concat(captionEmbeds);
// If the caption embeds array isn't empty filter through them to check if any is a Twitter/X or Meta url.
if (captionEmbeds !== null && captionEmbeds.length) {
const metaLinks = captionEmbeds.filter(({ url }) => metaLinkCheck(url));
const twitterLinks = captionEmbeds.filter(({ url }) =>
twitterLinkCheck(url)
);
if (allEmbeds.length) {
const metaLinks = allEmbeds.filter(({ url }) => metaLinkCheck(url));
const twitterLinks = allEmbeds.filter(({ url }) => twitterLinkCheck(url));
const tiktokLinks = allEmbeds.filter(({ url }) => tiktokLinkCheck(url));
// Handle action and response if both meta and Twitter/X links are detected.
if (metaLinks.length && twitterLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Also Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.\n\nIf this was forwarded from a channel consider forwarding without the caption so the media isn't deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
}
// Handle action and response if only meta links are detected.
// Handles Meta & Facebook Links
if (metaLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\\n\nIf this was forwarded from a channel consider forwarding without the caption so the media isn't deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
deletedLinks += metaLinks.length;
}
// Handle action and response if only Twitter/X links are detected.
// Handles Twitter/X links.
if (twitterLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
deletedLinks += twitterLinks.length;
}
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.\n\nIf this was forwarded from a channel consider forwarding without the caption so the media isn't deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
// Handles TikTok links.
if (tiktokLinks.length) {
deletedLinks += tiktokLinks.length;
}
}
// If the embeds array isn't empty filter through them to check if any is a Twitter/X or Meta url.
if (embeds !== null && embeds.length) {
const metaLinks = embeds.filter(({ url }) => metaLinkCheck(url));
const twitterLinks = embeds.filter(({ url }) => twitterLinkCheck(url));
// Handle action and response if both meta and Twitter/X links are detected.
if (metaLinks.length && twitterLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
if (deletedLinks) {
ctx.msg.delete();
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Also Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
}
// Handle action and response if only meta links are detected.
if (metaLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
}
// Handle action and response if only Twitter/X links are detected.
if (twitterLinks.length) {
// Deletes the offending message.
ctx.msg.delete();
deletedLinks++;
await urql
.mutation(increment, { link: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
});
}
if (deletedLinks) {
return await urql
.mutation(addGroup, {
groupID,
groupName,
groupUsername,
mutationKey
})
.toPromise()
.then(() =>
urql.mutation(incrementGroup, {
return await urql
.mutation(addGroup, {
groupID,
groupName,
groupUsername,
mutationKey
})
.toPromise()
.then(() =>
urql
.mutation(incrementGroup, {
groupID,
linksDeleted: deletedLinks,
mutationKey
})
);
}
.then(
async () =>
await urql
.mutation(increment, { link: deletedLinks, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
// Replies to the user informing them of the action.
await ctx.reply(
`@${username} One or more links in your last message were on the banlist\\. Remember TikTok, Meta & Facebook, and Twitter\\/X links along with any reformatting services for them are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\.\n\nNo administration action was taken against you other than the message being deleted\\.\n\nIf this was forwarded from a channel consider forwarding without the caption so the media isn't deleted\\.`,
{ parse_mode: "MarkdownV2" }
);
}
})
)
);
}
}
});