feat: add hashtag removal utility and integrate it into caption formatting

This commit is contained in:
vchikalkin 2026-01-14 17:56:18 +03:00
parent 58dc5f5ae3
commit 816eca4da5
3 changed files with 8 additions and 1 deletions

View File

@ -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) => {

View File

@ -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;

View File

@ -0,0 +1,3 @@
export function removeHashtags(caption: string): string {
return caption.replaceAll(/#[\p{L}\p{N}_-]+/gu, '').trim();
}