mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 14:41:05 +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,
|
hitsPerPage: 25,
|
||||||
});
|
});
|
||||||
|
|
||||||
return interaction.respond(
|
return interaction.showChoices(
|
||||||
result.hits.map((hit: any) => {
|
result.hits.map((hit: any) => {
|
||||||
const name = getHitName(hit);
|
const name = getHitName(hit);
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,12 @@ export default {
|
||||||
if (!interaction.inGuild()) return;
|
if (!interaction.inGuild()) return;
|
||||||
const query = interaction.data.getFocused<string>().value;
|
const query = interaction.data.getFocused<string>().value;
|
||||||
if (!query) {
|
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);
|
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;
|
} satisfies SlashCommand;
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { getRandomBunEmoji, isBunOnlyLikeMessage, safeSlice } from "../util.ts";
|
||||||
|
|
||||||
const GITHUB_LINE_URL_REGEX =
|
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;
|
/(?: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 {
|
export default {
|
||||||
event: "messageCreate",
|
event: "messageCreate",
|
||||||
|
@ -18,6 +20,7 @@ export default {
|
||||||
|
|
||||||
function handleOthers(message: Message): void {
|
function handleOthers(message: Message): void {
|
||||||
handleGithubLink(message);
|
handleGithubLink(message);
|
||||||
|
handleTwitterLink(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleBunOnlyChannel(message: Message): boolean {
|
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