diff --git a/src/commands/slash/Main/hub/create.ts b/src/commands/slash/Main/hub/create.ts index d5a94f5ec..070d95340 100644 --- a/src/commands/slash/Main/hub/create.ts +++ b/src/commands/slash/Main/hub/create.ts @@ -3,7 +3,6 @@ import { RegisterInteractionHandler } from '#main/decorators/Interaction.js'; import { HubSettingsBits } from '#main/modules/BitFields.js'; import { CustomID } from '#utils/CustomID.js'; import db from '#utils/Db.js'; -import { checkAndFetchImgurUrl } from '#utils/ImageUtils.js'; import { t } from '#utils/Locale.js'; import { ActionRowBuilder, @@ -122,8 +121,9 @@ export default class Create extends HubCommand { return; } - const iconUrl = icon ? await checkAndFetchImgurUrl(icon) : undefined; - const bannerUrl = banner ? await checkAndFetchImgurUrl(banner) : undefined; + const imgurRegex = Constants.Regex.ImgurImage; + const iconUrl = icon.length > 0 ? icon.match(imgurRegex)?.[0] : false; + const bannerUrl = banner.length > 0 ? banner.match(imgurRegex)?.[0] : false; // TODO: create a gif showing how to get imgur links if (iconUrl === false || bannerUrl === false) { diff --git a/src/config/Constants.ts b/src/config/Constants.ts index b366cedd3..16b497fbd 100644 --- a/src/config/Constants.ts +++ b/src/config/Constants.ts @@ -37,7 +37,19 @@ export const enum ConnectionMode { } /** Unicode emojis for numbers */ -export const numberEmojis = ['0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟'] as const; +export const numberEmojis = [ + '0️⃣', + '1️⃣', + '2️⃣', + '3️⃣', + '4️⃣', + '5️⃣', + '6️⃣', + '7️⃣', + '8️⃣', + '9️⃣', + '🔟', +] as const; export default { isDevBuild: process.env.NODE_ENV === 'development', @@ -57,9 +69,6 @@ export default { StaticImageUrl: /\bhttps?:\/\/\S+?\.(?:png|jpe?g|webp)(?:\?\S+)?\b/, /** ignores giphy and tenor */ Links: /https?:\/\/(?!tenor\.com|giphy\.com)\S+/g, - /** matches imgur urls */ - ImgurLinks: - /(?:https?:\/\/)?(?:www\.)?imgur\.com\/(?:a\/|gallery\/)?([a-zA-Z0-9]+)(?:\.[a-zA-Z]+)?/i, /** matches profanity words */ Profanity: new RegExp(profanity.map((word) => `\\b${word}\\b`).join('|'), 'gi'), /** matches slurs */ @@ -72,6 +81,7 @@ export default { SplitWords: /\b/, Hexcode: /^#[0-9A-F]{6}$/i, ChannelMention: /<#|!|>/g, + ImgurImage: /https?:\/\/i\.imgur\.com\/[a-zA-Z0-9]+\.((jpg)|(jpeg)|(png)|(gif))/g, }, Links: { diff --git a/src/utils/ImageUtils.ts b/src/utils/ImageUtils.ts index db770a043..71a9efcb8 100644 --- a/src/utils/ImageUtils.ts +++ b/src/utils/ImageUtils.ts @@ -1,34 +1,6 @@ import Constants from '#main/config/Constants.js'; import Logger from '#utils/Logger.js'; -type ImgurResponse = { data: { link: string; nsfw: boolean; cover: string } }; - -export const checkAndFetchImgurUrl = async (url: string): Promise => { - const regex = Constants.Regex.ImgurLinks; - const match = url.match(regex); - - if (!match?.[1]) return false; - - const type = match[0].includes('/a/') || match[0].includes('/gallery/') ? 'gallery' : 'image'; - const response = await fetch(`https://api.imgur.com/3/${type}/${match[1]}`, { - headers: { - Authorization: `Client-ID ${process.env.IMGUR_CLIENT_ID}`, - }, - }); - - const res = (await response.json().catch(() => null)) as ImgurResponse; - - if (!res || res.data?.nsfw) { - return false; - } - else if (res.data.cover) { - // refetch the cover image for albuns/galleries - return await checkAndFetchImgurUrl(`https://imgur.com/${res.data.cover}`); - } - - return res.data.link; -}; - /** * Returns the URL of an attachment in a message, if it exists. * @param message The message to search for an attachment URL.