Skip to content

Commit

Permalink
finish adding jsdoc everywhere I think
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 8, 2023
1 parent 10f5cdf commit f9c77c4
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/helpers/functions/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/functions/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/images/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/images/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/images/magnify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
15 changes: 15 additions & 0 deletions src/helpers/images/multiply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions src/helpers/images/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/images/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface TileOptions {
}

/**
* Tile an image
* @author Juknum
* @param origin what to tile
* @param options what shape and randomness
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/images/zipToAttachmentBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttachmentBuilder[]> => {
let output: AttachmentBuilder[] = [];
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/utility/random.ts
Original file line number Diff line number Diff line change
@@ -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 = <T>(arr: T[]): T => arr[randint(0, arr.length - 1)];
/** return a randomly shuffled version of a provided array */
export const shuffle = <T>(arr: T[]): T[] => arr.sort(() => randint(-1, 1));

0 comments on commit f9c77c4

Please sign in to comment.