mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-10 01:08:07 +01:00
feat: twitter links got better
also fix show choices
This commit is contained in:
parent
7a81256260
commit
5593d9259f
3 changed files with 18 additions and 4 deletions
|
@ -28,7 +28,7 @@ export default {
|
|||
hitsPerPage: 25,
|
||||
});
|
||||
|
||||
return interaction.respond(
|
||||
return interaction.showChoices(
|
||||
result.hits.map((hit: any) => {
|
||||
const name = getHitName(hit);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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}`
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue