Update action flow for detected links to prevent bot/program crashing.
Main / build-and-push-docker-image (20.x) (push) Successful in 4m9s
Main / build-and-push-docker-image (20.x) (push) Successful in 4m9s
This commit is contained in:
@@ -26,7 +26,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
|
||||
const groupName = ctx.chat?.title || "";
|
||||
const groupID = ctx.chat?.id.toString() || "";
|
||||
const groupUsername = ctx.chat?.username || "";
|
||||
let deletedLinks = 0;
|
||||
let detectedLinks = 0;
|
||||
|
||||
const username = ctx.msg.from?.username;
|
||||
|
||||
@@ -39,7 +39,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
|
||||
: [];
|
||||
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 the all embeds array isn't empty filter through them to check for every type of disallowed link.
|
||||
if (allEmbeds.length) {
|
||||
const metaLinks = allEmbeds.filter(({ url }) => metaLinkCheck(url));
|
||||
const twitterLinks = allEmbeds.filter(({ url }) => twitterLinkCheck(url));
|
||||
@@ -47,23 +47,21 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
|
||||
|
||||
// Handles Meta & Facebook Links
|
||||
if (metaLinks.length) {
|
||||
deletedLinks += metaLinks.length;
|
||||
detectedLinks += metaLinks.length;
|
||||
}
|
||||
|
||||
// Handles Twitter/X links.
|
||||
if (twitterLinks.length) {
|
||||
deletedLinks += twitterLinks.length;
|
||||
detectedLinks += twitterLinks.length;
|
||||
}
|
||||
|
||||
// Handles TikTok links.
|
||||
if (tiktokLinks.length) {
|
||||
deletedLinks += tiktokLinks.length;
|
||||
detectedLinks += tiktokLinks.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedLinks) {
|
||||
ctx.msg.delete();
|
||||
|
||||
if (detectedLinks) {
|
||||
return await urql
|
||||
.mutation(addGroup, {
|
||||
groupID,
|
||||
@@ -76,13 +74,13 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
|
||||
urql
|
||||
.mutation(incrementGroup, {
|
||||
groupID,
|
||||
linksDeleted: deletedLinks,
|
||||
linksDeleted: detectedLinks,
|
||||
mutationKey
|
||||
})
|
||||
.then(
|
||||
async () =>
|
||||
await urql
|
||||
.mutation(increment, { link: deletedLinks, mutationKey })
|
||||
.mutation(increment, { link: detectedLinks, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
@@ -91,6 +89,9 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
|
||||
`@${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" }
|
||||
);
|
||||
|
||||
// Deletes the offending message
|
||||
ctx.msg.delete();
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user