From 705bb73f1982276c901775f35850f5eebe26060e Mon Sep 17 00:00:00 2001 From: Lucid <72232219+werewolfkid@users.noreply.github.com> Date: Wed, 1 Apr 2026 17:11:37 -0400 Subject: [PATCH] Update action flow for detected links to prevent bot/program crashing. --- package.json | 2 +- src/bot/features/embedCheck.ts | 21 +++++++++++---------- src/bot/features/metaBanlist.ts | 5 +++-- src/bot/features/tiktokBanlist.ts | 5 +++-- src/bot/features/twitterBanlist.ts | 5 +++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 9b0b75a..2ef7cbe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "no-twitter-bot", "type": "module", - "version": "3.1.0", + "version": "3.2.0", "private": true, "packageManager": "yarn@4.12.0", "description": "This grammY powered Telegram bot is designed to delete Twitter/X links and reformat services from whitelisted groups. This one is the main bot for the LCM Telegram groups/communities.", diff --git a/src/bot/features/embedCheck.ts b/src/bot/features/embedCheck.ts index 6b9e9d9..c8fa073 100644 --- a/src/bot/features/embedCheck.ts +++ b/src/bot/features/embedCheck.ts @@ -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(); } }) ) diff --git a/src/bot/features/metaBanlist.ts b/src/bot/features/metaBanlist.ts index 600bc33..5f597cb 100644 --- a/src/bot/features/metaBanlist.ts +++ b/src/bot/features/metaBanlist.ts @@ -25,8 +25,6 @@ feature.hears( if (ctx.chat && ctx.msg) { const username = ctx.msg.from?.username; - // Deletes the offending message. - ctx.msg.delete(); return await urql .mutation(increment, { link: 1, mutationKey }) @@ -43,6 +41,9 @@ feature.hears( const groupID = ctx.chat?.id.toString() || ""; const groupUsername = ctx.chat?.username || ""; + // Deletes the offending message. + ctx.msg.delete(); + return await urql .mutation(addGroup, { groupID, diff --git a/src/bot/features/tiktokBanlist.ts b/src/bot/features/tiktokBanlist.ts index 21b9ad1..478a811 100644 --- a/src/bot/features/tiktokBanlist.ts +++ b/src/bot/features/tiktokBanlist.ts @@ -25,8 +25,6 @@ feature.hears( if (ctx.chat && ctx.msg) { const username = ctx.msg.from?.username; - // Deletes the offending message. - ctx.msg.delete(); return await urql .mutation(increment, { link: 1, mutationKey }) @@ -43,6 +41,9 @@ feature.hears( const groupID = ctx.chat?.id.toString() || ""; const groupUsername = ctx.chat?.username || ""; + // Deletes the offending message. + ctx.msg.delete(); + return await urql .mutation(addGroup, { groupID, diff --git a/src/bot/features/twitterBanlist.ts b/src/bot/features/twitterBanlist.ts index 4d8ce08..b7cf5f7 100644 --- a/src/bot/features/twitterBanlist.ts +++ b/src/bot/features/twitterBanlist.ts @@ -25,8 +25,6 @@ feature.hears( if (ctx.chat && ctx.msg) { const username = ctx.msg.from?.username; - // Deletes the offending message. - ctx.msg.delete(); return await urql .mutation(increment, { link: 1, mutationKey }) @@ -43,6 +41,9 @@ feature.hears( const groupID = ctx.chat?.id.toString() || ""; const groupUsername = ctx.chat?.username || ""; + // Deletes the offending message. + ctx.msg.delete(); + return await urql .mutation(addGroup, { groupID,