From f9c77c4b68ab134a48d7989cbc2c4c8fd05afc6e Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Sun, 8 Oct 2023 16:00:33 -0700 Subject: [PATCH] finish adding jsdoc everywhere I think --- src/helpers/functions/errorHandler.ts | 2 +- src/helpers/functions/missing.ts | 3 ++- src/helpers/images/animate.ts | 7 +++++++ src/helpers/images/colors.ts | 4 ++++ src/helpers/images/magnify.ts | 2 +- src/helpers/images/multiply.ts | 15 +++++++++++++++ src/helpers/images/palette.ts | 18 +++++++++++++++--- src/helpers/images/tile.ts | 14 ++++++++++++++ src/helpers/images/zipToAttachmentBuilders.ts | 4 ++-- src/helpers/utility/random.ts | 3 +++ 10 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/helpers/functions/errorHandler.ts b/src/helpers/functions/errorHandler.ts index 28443b9e7..aa3b133f9 100644 --- a/src/helpers/functions/errorHandler.ts +++ b/src/helpers/functions/errorHandler.ts @@ -112,7 +112,7 @@ export const logConstructor = ( }; /** - * Logs errors to a given error channel + * Handle and log errors * @author Juknum * @param client discord client * @param error error description diff --git a/src/helpers/functions/missing.ts b/src/helpers/functions/missing.ts index aa1cf0c6c..a98bd4bf9 100644 --- a/src/helpers/functions/missing.ts +++ b/src/helpers/functions/missing.ts @@ -135,7 +135,8 @@ export const compute = async ( const versions: string[] = ( await axios.get(`${client.tokens.apiUrl}settings/versions.${edition}`) ).data; - if (!versions.includes(version)) version = versions[0]; // latest version if versions doesn't include version (unexisting/unsupported) + // latest version if versions doesn't include version (unexisting/unsupported) + if (!versions.includes(version)) version = versions[0]; await callback(`Updating packs with latest version of \`${version}\` known...`).catch( (err: any) => Promise.reject(err), ); diff --git a/src/helpers/images/animate.ts b/src/helpers/images/animate.ts index 780d154da..1fcff28f2 100644 --- a/src/helpers/images/animate.ts +++ b/src/helpers/images/animate.ts @@ -129,6 +129,13 @@ export async function animate(baseCanvas: Canvas | Image, mcmeta: MCMETA): Promi return encoder.out.getData(); } +/** + * Animate a given image into a sendable gif + * @param baseCanvas tilesheet to animate + * @param mcmeta how to animate it + * @param name what name the attachment should have + * @returns sendable gif attachment + */ export async function animateToAttachment( baseCanvas: Image | Canvas, mcmeta: MCMETA, diff --git a/src/helpers/images/colors.ts b/src/helpers/images/colors.ts index 70889954a..dcb65e5c9 100644 --- a/src/helpers/images/colors.ts +++ b/src/helpers/images/colors.ts @@ -36,6 +36,10 @@ interface ColorManagerOptions { cmyk?: { c: number; m: number; y: number; k: number }; } +/** + * Convert and handle colors + * @author Nick + */ export default class ColorManager { private color: RGBA; diff --git a/src/helpers/images/magnify.ts b/src/helpers/images/magnify.ts index 0ffce9761..b9f744c18 100644 --- a/src/helpers/images/magnify.ts +++ b/src/helpers/images/magnify.ts @@ -11,7 +11,7 @@ export interface MagnifyOptions { * The actual magnification function * @author Juknum, Evorp * @param origin url, image, or buffer to magnify - * @param options + * @param options additional options * @returns buffer for magnified image */ export async function magnify(origin: ImageSource, options: MagnifyOptions = {}) { diff --git a/src/helpers/images/multiply.ts b/src/helpers/images/multiply.ts index 1f2bc6811..d4f746516 100644 --- a/src/helpers/images/multiply.ts +++ b/src/helpers/images/multiply.ts @@ -40,6 +40,13 @@ export const mcColorsOptions: { name: string; value: string }[] = Object.keys(mc }, ); +/** + * Tint a grayscale image with a provided color + * @author Nick, Evorp + * @param origin what to multiply over + * @param color what color to multiply + * @returns multiplied image + */ export async function multiply(origin: ImageSource, color: string) { const imageToDraw = await loadImage(origin); const canvas = createCanvas(imageToDraw.width, imageToDraw.height); @@ -71,6 +78,14 @@ export async function multiply(origin: ImageSource, color: string) { return canvas.toBuffer("image/png"); } +/** + * Multiply a given image into a sendable attachment + * @author Evorp + * @param origin what to multiply over + * @param color color to multiply + * @param name attachment name + * @returns sendable attachment + */ export async function multiplyToAttachment( origin: ImageSource, color: string, diff --git a/src/helpers/images/palette.ts b/src/helpers/images/palette.ts index 2cb26fa84..be0114d91 100644 --- a/src/helpers/images/palette.ts +++ b/src/helpers/images/palette.ts @@ -34,10 +34,10 @@ export interface AllColors { } /** - * Sends an ephemeral message with the palette of a given image url + * Create a palette of colors and additional information for a given image * @author Juknum, Evorp - * @param options image info - * @returns slash command attachment compatible embed/attachment data + * @param origin image to find palette of + * @returns embed and attachment */ export async function palette(origin: ImageSource) { const imageToDraw = await loadImage(origin); @@ -176,6 +176,13 @@ export async function palette(origin: ImageSource) { return { image: colorCanvas.toBuffer("image/png"), embed }; } +/** + * Get the color palette of an image + * @author Evorp + * @param origin image to find palette of + * @param name attachment name + * @returns sendable attachment and data + */ export async function paletteToAttachment( origin: ImageSource, name = "palette.png", @@ -186,6 +193,11 @@ export async function paletteToAttachment( return [new AttachmentBuilder(image, { name }), embed]; } +/** + * Warn the user that the image is too large + * @author Evorp + * @param interaction interaction to reply to + */ export async function paletteTooBig( interaction: | ButtonInteraction diff --git a/src/helpers/images/tile.ts b/src/helpers/images/tile.ts index 42fda96f6..c1362f70f 100644 --- a/src/helpers/images/tile.ts +++ b/src/helpers/images/tile.ts @@ -18,6 +18,7 @@ interface TileOptions { } /** + * Tile an image * @author Juknum * @param origin what to tile * @param options what shape and randomness @@ -123,6 +124,14 @@ export async function tile(origin: ImageSource, options: TileOptions = {}): Prom return canvas.toBuffer("image/png"); } +/** + * Tile an image with specified parameters + * @author Evorp + * @param origin image to tile + * @param options how to tile it + * @param name what the attachment should be called + * @returns tiled image as sendable attachment + */ export async function tileToAttachment( origin: ImageSource, options?: TileOptions, @@ -134,6 +143,11 @@ export async function tileToAttachment( return new AttachmentBuilder(buf, { name }); } +/** + * Warn the user that the image is too large + * @author Evorp + * @param interaction interaction to reply to + */ export async function tileTooBig( interaction: | ButtonInteraction diff --git a/src/helpers/images/zipToAttachmentBuilders.ts b/src/helpers/images/zipToAttachmentBuilders.ts index 7eab83e09..3767bf2f5 100644 --- a/src/helpers/images/zipToAttachmentBuilders.ts +++ b/src/helpers/images/zipToAttachmentBuilders.ts @@ -3,10 +3,10 @@ import { AttachmentBuilder } from "discord.js"; import JSZip from "jszip"; /** - * Convert a zip file of images into valid attachmentbuilders + * Convert a zip file of images into usable attachments * @author Juknum * @param url zip url - * @returns + * @returns array of attachments */ export const zipToAttachmentBuilders = async (url: string): Promise => { let output: AttachmentBuilder[] = []; diff --git a/src/helpers/utility/random.ts b/src/helpers/utility/random.ts index 67f684771..cc25da94b 100644 --- a/src/helpers/utility/random.ts +++ b/src/helpers/utility/random.ts @@ -1,4 +1,7 @@ +/** random integer between the given start and stop points */ export const randint = (start: number, stop: number) => Math.floor(start + Math.random() * (stop - start + 1)); +/** pick a random item out of an array */ export const choice = (arr: T[]): T => arr[randint(0, arr.length - 1)]; +/** return a randomly shuffled version of a provided array */ export const shuffle = (arr: T[]): T[] => arr.sort(() => randint(-1, 1));