Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/commands/slash/Main/hub/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 14 additions & 4 deletions src/config/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 */
Expand All @@ -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: {
Expand Down
28 changes: 0 additions & 28 deletions src/utils/ImageUtils.ts
Original file line number Diff line number Diff line change
@@ -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<string | false> => {
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.
Expand Down