From 5593d9259ffed500f0195802adf643ca78292ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl=20=28xHyroM=29?= Date: Tue, 16 Jan 2024 19:43:13 +0100 Subject: [PATCH] feat: twitter links got better also fix show choices --- src/commands/docs.tsx | 2 +- src/commands/tag.tsx | 6 +++--- src/listeners/message_create.tsx | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/commands/docs.tsx b/src/commands/docs.tsx index cd251a5..76fb832 100644 --- a/src/commands/docs.tsx +++ b/src/commands/docs.tsx @@ -28,7 +28,7 @@ export default { hitsPerPage: 25, }); - return interaction.respond( + return interaction.showChoices( result.hits.map((hit: any) => { const name = getHitName(hit); diff --git a/src/commands/tag.tsx b/src/commands/tag.tsx index 91f76bb..e1d81c1 100644 --- a/src/commands/tag.tsx +++ b/src/commands/tag.tsx @@ -43,12 +43,12 @@ export default { if (!interaction.inGuild()) return; const query = interaction.data.getFocused().value; if (!query) { - return await interaction.respond(getTags(interaction.channel, 25)); + return await interaction.showChoices(getTags(interaction.channel, 25)); } const tags = searchTag(interaction.channel, query, true); - if (tags.length > 0) return await interaction.respond(tags); + if (tags.length > 0) return await interaction.showChoices(tags); - return await interaction.respond(getTags(interaction.channel, 25)); + return await interaction.showChoices(getTags(interaction.channel, 25)); }, } satisfies SlashCommand; diff --git a/src/listeners/message_create.tsx b/src/listeners/message_create.tsx index f85eefe..b3335bb 100644 --- a/src/listeners/message_create.tsx +++ b/src/listeners/message_create.tsx @@ -6,6 +6,8 @@ import { getRandomBunEmoji, isBunOnlyLikeMessage, safeSlice } from "../util.ts"; const GITHUB_LINE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?.+?)#L(?\d+)[-~]?L?(?\d*)/i; +const TWITTER_TWEET_URL_REGEX = + /https:\/\/(?:www\.)?(?:twitter|x)\.com\/(?[a-zA-Z0-9-_]+)\/status\/(?\d+)/i; export default { event: "messageCreate", @@ -18,6 +20,7 @@ export default { function handleOthers(message: Message): void { handleGithubLink(message); + handleTwitterLink(message); } function handleBunOnlyChannel(message: Message): boolean { @@ -100,3 +103,14 @@ async function handleGithubLink(message: Message): Promise { ], }); } + +function handleTwitterLink(message: Message): void { + if (!message.content) return; + + const match = TWITTER_TWEET_URL_REGEX.exec(message.content); + if (!match || !match.groups?.user || !match.groups?.id) return; + + message.reply( + `https://fxtwitter.com/${match.groups.user}/status/${match.groups.id}` + ); +}