Skip to content

Commit

Permalink
fix /texture with animations
Browse files Browse the repository at this point in the history
much easier to debug with the new bot lol
  • Loading branch information
3vorp committed Oct 10, 2023
1 parent da21ad5 commit e6f399c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/commands/images/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const command: SlashCommand = {
}

const mcmeta: MCMETA = mcmetaList[style];
const file = await animateToAttachment(await loadImage(magnified), mcmeta, `${style}.gif`);
const file = await animateToAttachment(magnified, mcmeta, `${style}.gif`);
await interaction
.editReply({ files: [file] })
.then((message: Message) => message.deleteButton());
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/functions/getTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Contributor, Tokens } from "@interfaces";
import axios from "axios";
import getDimensions from "@images/getDimensions";
import { APIEmbedField, AttachmentBuilder, Guild } from "discord.js";
import { magnifyToAttachment } from "@images/magnify";
import { magnify, magnifyToAttachment } from "@images/magnify";
import { ISizeCalculationResult } from "image-size/dist/types/interface";
import { colors } from "@utility/colors";
import { Texture, Contribution } from "@interfaces";
Expand Down Expand Up @@ -84,7 +84,7 @@ export const getTexture = async (options: {
.setURL(`https://webapp.faithfulpack.net/#/gallery/java/32x/latest/all/?show=${texture.id}`)
.addFields({ name: "Resolution", value: `${dimension.width}×${dimension.height}` })
.setThumbnail(textureURL)
.setImage(`attachment://magnified.${animated ? "gif" : "png"}`);
.setImage(`attachment://${animated ? "animated.gif" : "magnified.png"}`);

let mainContribution: Contribution;
if (allContributions.length) {
Expand Down Expand Up @@ -123,7 +123,8 @@ export const getTexture = async (options: {
value: `\`\`\`json\n${JSON.stringify(mcmeta.animation)}\`\`\``,
});

files.push(await animateToAttachment(await loadImage(textureURL), mcmeta));
const { magnified } = await magnify(textureURL, { isAnimation: true });
files.push(await animateToAttachment(magnified, mcmeta));
} else files.push(await magnifyToAttachment(textureURL));

return { embeds: [embed], files: files, components: [textureButtons], ephemeral: false };
Expand Down
10 changes: 6 additions & 4 deletions src/helpers/images/animate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Canvas, Image, createCanvas } from "@napi-rs/canvas";
import { createCanvas, loadImage } from "@napi-rs/canvas";
import GIFEncoder from "./GIFEncoder";
import { AttachmentBuilder } from "discord.js";
import { ImageSource } from "@helpers/getImage";

export interface MCMETA {
animation: {
Expand All @@ -15,11 +16,12 @@ export interface MCMETA {
/**
* Animate a given image with a given mcmeta
* @author Superboxer4, Evorp, Juknum
* @param baseCanvas tilesheet to animate
* @param origin tilesheet to animate
* @param mcmeta how you want it animated
* @returns animated GIF as buffer
*/
export async function animate(baseCanvas: Canvas | Image, mcmeta: MCMETA): Promise<Buffer> {
export async function animate(origin: ImageSource, mcmeta: MCMETA): Promise<Buffer> {
const baseCanvas = await loadImage(origin);
if (!mcmeta.animation) mcmeta.animation = {};

if (!mcmeta.animation?.width) mcmeta.animation.width = baseCanvas.width;
Expand Down Expand Up @@ -137,7 +139,7 @@ export async function animate(baseCanvas: Canvas | Image, mcmeta: MCMETA): Promi
* @returns sendable gif attachment
*/
export async function animateToAttachment(
baseCanvas: Image | Canvas,
baseCanvas: ImageSource,
mcmeta: MCMETA,
name = "animated.gif",
) {
Expand Down

0 comments on commit e6f399c

Please sign in to comment.