all repos — stealth-developers @ b6e0941babbabd8366ca160ca09bb330a1698eb9

feat: use cdn links for highlighting
vi v@vt3e.cat
Wed, 04 Mar 2026 23:52:48 +0000
commit

b6e0941babbabd8366ca160ca09bb330a1698eb9

parent

2080a689c216d781e762adf4c86617edf7311c7e

1 files changed, 40 insertions(+), 4 deletions(-)

jump to
M src/interactions/menus/highlight.tssrc/interactions/menus/highlight.ts

@@ -13,9 +13,44 @@ .setName("Highlight Clip")

.setType(ApplicationCommandType.Message); function extractVideoLinks(message: { content: string }): string[] { - const urlRegex = - /https?:\/\/(?:www\.)?(?:youtube\.com\/watch\?v=[\w-]+|youtu\.be\/[\w-]+|medal\.tv\/(?:games\/[\w-]+\/clips\/[\w-]+|g\/[\w-]+|clips\/[\w-]+))/gi; - return Array.from(message.content.matchAll(urlRegex)).map((m) => m[0]); + const domains = [ + "youtube.com", + "youtu.be", + "medal.tv", + "cdn.discordapp.com", + "twitch.tv", + "clips.twitch.tv", + ]; + + const tokens = message.content.split(/\s+/); + const found = new Set<string>(); + + for (const raw of tokens) { + let t = raw + .replace(/^<+/, "") + .replace(/>+$/, "") + .replace(/^[('"`]+/, "") + .replace(/['")`.,;:!]+$/, ""); + if (!t) continue; + + const lower = t.toLowerCase(); + if (!domains.some((d) => lower.includes(d))) continue; + + if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(t)) { + t = `https://${t}`; + } + + try { + const url = new URL(t); + if (!domains.some((d) => url.hostname.toLowerCase().includes(d))) + continue; + + const normalized = url.href.replace(/\/$/, ""); + found.add(normalized); + } catch {} + } + + return Array.from(found); } function isVideoAttachment(attachment: Attachment): boolean {

@@ -96,6 +131,8 @@ const files = Array.from(videoAttachments.values()).map((a) => a.url);

const author = `<@${targetMessage.author.id}>`; const jumpUrl = targetMessage.url; + if (videoLinks.length === 0) videoLinks.push(...files); + const videoLinksText = videoLinks .map((link) => `• [Video Link](${link})`) .join(" ");

@@ -104,7 +141,6 @@

try { const msg = await highlightsChannel.send({ content: description, - files: files.length > 0 ? files : undefined, allowedMentions: { users: [targetMessage.author.id] }, });