feat: twitter links got better

also fix show choices
This commit is contained in:
Jozef Steinhübl 2024-01-16 19:43:13 +01:00
parent 7a81256260
commit 5593d9259f
No known key found for this signature in database
GPG key ID: E944BC293F5FF7E7
3 changed files with 18 additions and 4 deletions

View file

@ -28,7 +28,7 @@ export default {
hitsPerPage: 25,
});
return interaction.respond(
return interaction.showChoices(
result.hits.map((hit: any) => {
const name = getHitName(hit);

View file

@ -43,12 +43,12 @@ export default {
if (!interaction.inGuild()) return;
const query = interaction.data.getFocused<string>().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;

View file

@ -6,6 +6,8 @@ import { getRandomBunEmoji, isBunOnlyLikeMessage, safeSlice } from "../util.ts";
const GITHUB_LINE_URL_REGEX =
/(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?<repo>[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?<path>.+?)#L(?<first_line_number>\d+)[-~]?L?(?<second_line_number>\d*)/i;
const TWITTER_TWEET_URL_REGEX =
/https:\/\/(?:www\.)?(?:twitter|x)\.com\/(?<user>[a-zA-Z0-9-_]+)\/status\/(?<id>\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<void> {
],
});
}
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}`
);
}