From cc4abb338531599830f9980a00c9154fa2f4a4ea Mon Sep 17 00:00:00 2001 From: Lucid Date: Mon, 26 Jan 2026 19:53:09 -0500 Subject: [PATCH] Added tiktok filter --- src/bot/features/tiktokBanlist.ts | 67 +++++++++++++++++++++++++++++++ src/bot/index.ts | 12 +++--- src/lib/twitterLinkCheck.ts | 2 +- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/bot/features/tiktokBanlist.ts diff --git a/src/bot/features/tiktokBanlist.ts b/src/bot/features/tiktokBanlist.ts new file mode 100644 index 0000000..34f0c0f --- /dev/null +++ b/src/bot/features/tiktokBanlist.ts @@ -0,0 +1,67 @@ +import { Composer } from "grammy"; +import type { Context } from "#root/bot/context.js"; +import { logHandle } from "#root/bot/helpers/logging.js"; +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 { tiktokRegex } from "#root/lib/tiktokLinkCheck.js"; + +const composer = new Composer(); + +const feature = composer.chatType(["group", "supergroup"]); + +/** + * What triggers this feature and adds to the log when it has been triggered. + * The trigger uses the global Twitter regex to detect TikTok links within messages. + */ +feature.hears( + tiktokRegex, + logHandle("banlist-detection-tiktok"), + async (ctx: Context) => { + const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + + await urql.mutation(increment, { trigger: true, mutationKey }); + + if (ctx.chat && ctx.msg) { + const username = ctx.msg.from?.username; + // Deletes the offending message. + ctx.msg.delete(); + + return await urql + .mutation(increment, { link: true, mutationKey }) + .toPromise() + .then(async () => { + if (ctx.msg && ctx.chat) { + // Replies to the user informing them of the action. + await ctx.reply( + `@${username} TikTok links 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" } + ); + + const groupName = ctx.chat?.title || ""; + const groupID = ctx.chat?.id.toString() || ""; + const groupUsername = ctx.chat?.username || ""; + + return await urql + .mutation(addGroup, { + groupID, + groupName, + groupUsername, + mutationKey + }) + .toPromise() + .then(() => + urql.mutation(incrementGroup, { + groupID, + linksDeleted: 1, + mutationKey + }) + ); + } + }); + } + } +); + +export { composer as tiktokBanlist }; diff --git a/src/bot/index.ts b/src/bot/index.ts index 4aeabee..9ffb1d6 100644 --- a/src/bot/index.ts +++ b/src/bot/index.ts @@ -13,8 +13,9 @@ import { hydrate } from "@grammyjs/hydrate"; import { hydrateReply, parseMode } from "@grammyjs/parse-mode"; import { sequentialize } from "@grammyjs/runner"; import { MemorySessionStorage, Bot as TelegramBot } from "grammy"; -import { twitterBlacklist } from "./features/twitterBlacklist.js"; -import { metaBlacklist } from "./features/metaBlacklist.js"; +import { twitterBanlist } from "./features/twitterBanlist.js"; +import { metaBanlist } from "./features/metaBanlist.js"; +import { tiktokBanlist } from "./features/tiktokBanlist.js"; import { botInfoCommand } from "./features/botInfoCommand.js"; import { helpCommand } from "./features/helpCommand.js"; import { embedCheck } from "./features/embedCheck.js"; @@ -77,9 +78,10 @@ export function createBot( protectedBot.use(getGroupStats); protectedBot.use(statsSiteCommand); - // Blacklist Feature - protectedBot.use(twitterBlacklist); - protectedBot.use(metaBlacklist); + // banlist Feature + protectedBot.use(twitterBanlist); + protectedBot.use(metaBanlist); + protectedBot.use(tiktokBanlist); protectedBot.use(embedCheck); // must be the last handler diff --git a/src/lib/twitterLinkCheck.ts b/src/lib/twitterLinkCheck.ts index a633dce..4dabde3 100644 --- a/src/lib/twitterLinkCheck.ts +++ b/src/lib/twitterLinkCheck.ts @@ -4,7 +4,7 @@ const twitterRegex = /(x\.com|twitter\.com)/gi; /** * This function will check if a url matches Twitter/X services links using regex. * - * @param linkUrl representing a suspected blacklisted url + * @param linkUrl representing a suspected url on the banlist * @return flag */ const twitterLinkCheck = (linkUrl: string): boolean => {