diff --git a/lang/en-US/commands.json b/lang/en-US/commands.json index 8b4257a84..8ea339fe8 100644 --- a/lang/en-US/commands.json +++ b/lang/en-US/commands.json @@ -11,7 +11,7 @@ }, "images": { "too_big": "This image is too big to %ACTION%!", - "max_size": "The maximum size for an image is 512px²." + "max_size": "The maximum size for an image is 1024px²." }, "stats": { "footer": "Made with love", diff --git a/src/client/message.ts b/src/client/message.ts index 9d3d8c53c..0d92081c8 100644 --- a/src/client/message.ts +++ b/src/client/message.ts @@ -29,7 +29,7 @@ const ExtendedMessage = { this.components.at(-1).components[0].type === ComponentType.Button //checks there isn't a select menu ) { const deleteRow = ActionRowBuilder.from(this.components.at(-1)).addComponents( - hasAuthorID === true ? deleteMessage : deleteInteraction, + hasAuthorID ? deleteMessage : deleteInteraction, ); return this.edit({ @@ -40,7 +40,7 @@ const ExtendedMessage = { components: [ ...this.components, new ActionRowBuilder().addComponents([ - hasAuthorID === true ? deleteMessage : deleteInteraction, + hasAuthorID ? deleteMessage : deleteInteraction, ]), ], }); diff --git a/src/commands/images/magnify.ts b/src/commands/images/magnify.ts index 079cad271..fb3c3349a 100644 --- a/src/commands/images/magnify.ts +++ b/src/commands/images/magnify.ts @@ -1,9 +1,9 @@ import { SlashCommand } from "@interfaces"; -import { ActionRowBuilder, ButtonBuilder, SlashCommandBuilder } from "discord.js"; +import { SlashCommandBuilder } from "discord.js"; import { ChatInputCommandInteraction, Message } from "@client"; import { magnifyToAttachment } from "@images/magnify"; import getImage from "@helpers/getImage"; -import { tile, palette } from "@helpers/buttons"; +import { imageButtons } from "@helpers/buttons"; export const command: SlashCommand = { data: new SlashCommandBuilder() @@ -38,7 +38,7 @@ export const command: SlashCommand = { await interaction .editReply({ files: [file], - components: [new ActionRowBuilder().addComponents(palette)], + components: [imageButtons], }) .then((message: Message) => message.deleteButton()); }, diff --git a/src/components/buttons/image/magnify.ts b/src/components/buttons/image/magnify.ts index 9cdb8afb7..b9883d091 100644 --- a/src/components/buttons/image/magnify.ts +++ b/src/components/buttons/image/magnify.ts @@ -2,10 +2,8 @@ import { Component } from "@interfaces"; import { info } from "@helpers/logger"; import { Client, Message, ButtonInteraction, EmbedBuilder } from "@client"; import { magnifyToAttachment } from "@images/magnify"; -import { palette } from "@helpers/buttons"; +import { imageButtons } from "@helpers/buttons"; import getImage from "@helpers/getImage"; -import { ActionRowBuilder } from "discord.js"; -import { ButtonBuilder } from "discord.js"; export default { id: "magnify", @@ -25,7 +23,7 @@ export default { .setTimestamp(), ], files: [attachment], - components: [new ActionRowBuilder().addComponents(palette)], + components: [imageButtons], fetchReply: true, }) .then((message: Message) => { diff --git a/src/components/buttons/image/tile.ts b/src/components/buttons/image/tile.ts index 6caea9338..a6105107b 100644 --- a/src/components/buttons/image/tile.ts +++ b/src/components/buttons/image/tile.ts @@ -2,9 +2,7 @@ import { Component } from "@interfaces"; import { info } from "@helpers/logger"; import { Client, Message, ButtonInteraction, EmbedBuilder } from "@client"; import { tileToAttachment, tileTooBig } from "@images/tile"; -import { magnify, palette } from "@helpers/buttons"; -import { ActionRowBuilder } from "discord.js"; -import { ButtonBuilder } from "discord.js"; +import { imageButtons } from "@helpers/buttons"; import getImage from "@helpers/getImage"; export default { @@ -27,7 +25,7 @@ export default { .setTimestamp(), ], files: [attachment], - components: [new ActionRowBuilder().addComponents(magnify, palette)], + components: [imageButtons], fetchReply: true, }) .then((message: Message) => { diff --git a/src/helpers/images/palette.ts b/src/helpers/images/palette.ts index 5a0518503..2ac2adade 100644 --- a/src/helpers/images/palette.ts +++ b/src/helpers/images/palette.ts @@ -41,7 +41,8 @@ export interface AllColors { */ export async function palette(origin: ImageSource) { const imageToDraw = await loadImage(origin); - if (imageToDraw.width * imageToDraw.height > 262144) return { image: null, embed: null }; + // 1048576px is the same size as a magnified image + if (imageToDraw.width * imageToDraw.height > 1048576) return { image: null, embed: null }; const canvas: Canvas = createCanvas(imageToDraw.width, imageToDraw.height); const context = canvas.getContext("2d"); context.drawImage(imageToDraw, 0, 0); @@ -197,9 +198,7 @@ export async function paletteTooBig( embeds: [ new EmbedBuilder() .setTitle( - interaction - .strings() - .command.images.too_big.replace("%ACTION%", "take the palette of"), + interaction.strings().command.images.too_big.replace("%ACTION%", "take the palette of"), ) .setDescription(interaction.strings().command.images.max_size) .setColor(colors.red), diff --git a/src/helpers/images/tile.ts b/src/helpers/images/tile.ts index 62f964b55..7f46580c1 100644 --- a/src/helpers/images/tile.ts +++ b/src/helpers/images/tile.ts @@ -26,7 +26,8 @@ interface TileOptions { export async function tile(origin: ImageSource, options: TileOptions = {}): Promise { const input = await loadImage(origin).catch((err) => Promise.reject(err)); - if (input.width * input.height * 3 > 262144) return null; + // 1048576px is the same size as a magnified image + if (input.width * input.height * 3 > 1048576) return null; const canvas = createCanvas(input.width * 3, input.height * 3); const context = canvas.getContext("2d"); diff --git a/src/helpers/prefixCommandHandler.ts b/src/helpers/prefixCommandHandler.ts index 57d262fb4..cd69a7efc 100644 --- a/src/helpers/prefixCommandHandler.ts +++ b/src/helpers/prefixCommandHandler.ts @@ -3,8 +3,7 @@ import { magnifyToAttachment } from "./images/magnify"; import getImage from "./getImage"; import { tileToAttachment, tileTooBig } from "./images/tile"; import { paletteToAttachment, paletteTooBig } from "./images/palette"; -import { ActionRowBuilder, ButtonBuilder } from "discord.js"; -import { imageButtons, palette } from "./buttons"; +import { imageButtons } from "./buttons"; export default async function prefixCommandHandler(message: Message) { const args = message.content.split(" "); @@ -19,7 +18,7 @@ export default async function prefixCommandHandler(message: Message) { return await message .reply({ files: [await magnifyToAttachment(url)], - components: [new ActionRowBuilder().addComponents(palette)], + components: [imageButtons], }) .then((message: Message) => message.deleteButton()); case "t":