From 816eca4da5f988f5c2cee928564611686991012d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 14 Jan 2026 17:56:18 +0300 Subject: [PATCH] feat: add hashtag removal utility and integrate it into caption formatting --- apps/bot/src/bot/features/download.ts | 4 +++- apps/bot/src/constants/regex.ts | 2 ++ apps/bot/src/utils/text.ts | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 apps/bot/src/utils/text.ts diff --git a/apps/bot/src/bot/features/download.ts b/apps/bot/src/bot/features/download.ts index 4b4cab3..d942737 100644 --- a/apps/bot/src/bot/features/download.ts +++ b/apps/bot/src/bot/features/download.ts @@ -5,6 +5,7 @@ import { logHandle } from '../helpers/logging'; import { TTL_URLS } from '@/config/redis'; import { getInstagramDownloadUrl } from '@/utils/instagram'; import { getRedisInstance } from '@/utils/redis'; +import { removeHashtags } from '@/utils/text'; import { getTiktokDownloadUrl } from '@/utils/tiktok'; import { validateInstagramUrl, validateTikTokUrl, validateYoutubeUrl } from '@/utils/urls'; import { getYoutubeDownloadUrl } from '@/utils/youtube'; @@ -18,7 +19,8 @@ const redis = getRedisInstance(); // Форматирование подписи как expandable blockquote function formatCaption(caption: string) { - return fmt`${expandableBlockquote} ${caption} ${expandableBlockquote}`; + const cleanCaption = removeHashtags(caption); + return fmt`${expandableBlockquote} ${cleanCaption} ${expandableBlockquote}`; } feature.on('message:text', logHandle('download-message'), async (context) => { diff --git a/apps/bot/src/constants/regex.ts b/apps/bot/src/constants/regex.ts index a803d7e..a28c20b 100644 --- a/apps/bot/src/constants/regex.ts +++ b/apps/bot/src/constants/regex.ts @@ -7,3 +7,5 @@ export const INSTAGRAM_URL_REGEX = export const YOUTUBE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/))([\w-]{11})(?:[?&]\S*)?/u; + +export const TAGS = /#[\p{L}\p{N}_]+/gu; diff --git a/apps/bot/src/utils/text.ts b/apps/bot/src/utils/text.ts new file mode 100644 index 0000000..fc4b61c --- /dev/null +++ b/apps/bot/src/utils/text.ts @@ -0,0 +1,3 @@ +export function removeHashtags(caption: string): string { + return caption.replaceAll(/#[\p{L}\p{N}_-]+/gu, '').trim(); +}