From 6deb49d9bbd48b5710f80a7a3bfaa2d2d0042a4e Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Sat, 28 Oct 2023 14:40:10 -0700 Subject: [PATCH] pack types and remove unnecessary casts --- src/commands/developer/status.ts | 7 ++-- src/commands/faithful/about.ts | 7 ++-- src/commands/faithful/missing.ts | 8 ++-- src/commands/faithful/texture.ts | 4 +- src/commands/fun/order.ts | 7 ++-- .../buttons/general/deleteInteraction.ts | 7 ++-- .../buttons/general/deleteMessage.ts | 4 +- .../buttons/image/comparisonTemplate.ts | 4 +- src/components/buttons/image/magnify.ts | 2 +- src/components/buttons/image/palette.ts | 2 +- src/components/buttons/image/tile.ts | 2 +- src/components/buttons/poll/pollDelete.ts | 7 ++-- src/components/buttons/poll/pollVote.ts | 4 +- src/components/menus/compareSelect.ts | 6 +-- src/components/menus/cycleSelect.ts | 5 +-- src/components/menus/textureSelect.ts | 9 ++--- src/events/messageCreate.ts | 4 +- src/events/slashCommandUsed.ts | 4 +- src/helpers/functions/getTexture.ts | 8 +--- src/helpers/functions/missing.ts | 11 +++--- src/helpers/functions/textureComparison.ts | 6 +-- src/helpers/getImage.ts | 3 +- src/helpers/images/cycle.ts | 26 ++++++------- src/helpers/images/multiply.ts | 12 +++--- src/helpers/poll.ts | 7 ++-- src/helpers/utility/formatName.ts | 38 ++++++++++--------- src/interfaces/firestorm.ts | 38 +++++++++++-------- src/interfaces/submission.ts | 14 +++---- 28 files changed, 126 insertions(+), 130 deletions(-) diff --git a/src/commands/developer/status.ts b/src/commands/developer/status.ts index 92a55c1d7..80f56172c 100644 --- a/src/commands/developer/status.ts +++ b/src/commands/developer/status.ts @@ -18,9 +18,10 @@ export const command: SlashCommand = { .addChoices( ...Object.values(ActivityType) .filter((x) => typeof x == "string") - .map((i: string) => { - return { name: i, value: i }; - }), + .map((i: string) => ({ + name: i, + value: i, + })), ) .setRequired(true), ) diff --git a/src/commands/faithful/about.ts b/src/commands/faithful/about.ts index ecd46914a..8dc2ac4ae 100644 --- a/src/commands/faithful/about.ts +++ b/src/commands/faithful/about.ts @@ -80,9 +80,10 @@ export const command: SlashCommand = { ).flat(); // merge the two objects by id - const finalData = contributionData.map((contribution: Contribution) => { - return { ...contribution, ...textureData.find((val) => val?.id == contribution.texture) }; - }); + const finalData = contributionData.map((contribution: Contribution) => ({ + ...contribution, + ...textureData.find((val) => val?.id == contribution.texture), + })); let packCount = {}; let files: AttachmentBuilder[] | undefined; diff --git a/src/commands/faithful/missing.ts b/src/commands/faithful/missing.ts index c85c4ec81..b4747467b 100644 --- a/src/commands/faithful/missing.ts +++ b/src/commands/faithful/missing.ts @@ -1,4 +1,4 @@ -import { SlashCommand, SyncSlashCommandBuilder } from "@interfaces"; +import { FaithfulPack, SlashCommand, SyncSlashCommandBuilder } from "@interfaces"; import { Client, ChatInputCommandInteraction, EmbedBuilder } from "@client"; import { SlashCommandBuilder, Message, AttachmentBuilder } from "discord.js"; import { @@ -53,9 +53,7 @@ export const command: SlashCommand = { ...versions .sort(minecraftSorter) .reverse() // newest at top - .map((i: string) => { - return { name: i, value: i }; - }), + .map((i: string) => ({ name: i, value: i })), ) .setRequired(false), ) @@ -70,7 +68,7 @@ export const command: SlashCommand = { await interaction.deferReply(); const edition = interaction.options.getString("edition", true); - const pack = interaction.options.getString("pack", true); + const pack = interaction.options.getString("pack", true) as FaithfulPack; const version = interaction.options.getString("version") ?? "latest"; const updateChannels = version === "latest"; diff --git a/src/commands/faithful/texture.ts b/src/commands/faithful/texture.ts index 68bba45fe..b8dae3584 100644 --- a/src/commands/faithful/texture.ts +++ b/src/commands/faithful/texture.ts @@ -1,4 +1,4 @@ -import { SlashCommand } from "@interfaces"; +import { FaithfulPack, SlashCommand } from "@interfaces"; import { SlashCommandBuilder } from "discord.js"; import { ChatInputCommandInteraction, Message } from "@client"; import { getTexture } from "@functions/getTexture"; @@ -45,7 +45,7 @@ export const command: SlashCommand = { const replyOptions = await getTexture( interaction, results[0], - interaction.options.getString("pack", true), + interaction.options.getString("pack", true) as FaithfulPack, ); // no results found diff --git a/src/commands/fun/order.ts b/src/commands/fun/order.ts index 266547a9b..60d4bef4f 100644 --- a/src/commands/fun/order.ts +++ b/src/commands/fun/order.ts @@ -41,9 +41,10 @@ export const command: SlashCommand = { .setName("item") .setDescription("The item you want.") .addChoices( - ...Object.keys(options).map((option) => { - return { name: option, value: option }; - }), + ...Object.keys(options).map((option) => ({ + name: option, + value: option, + })), ) .setRequired(true), ), diff --git a/src/components/buttons/general/deleteInteraction.ts b/src/components/buttons/general/deleteInteraction.ts index 8b42294db..039b680ff 100644 --- a/src/components/buttons/general/deleteInteraction.ts +++ b/src/components/buttons/general/deleteInteraction.ts @@ -1,15 +1,14 @@ import { Component } from "@interfaces"; import { info } from "@helpers/logger"; -import { Client, Message, ButtonInteraction } from "@client"; -import { MessageInteraction } from "discord.js"; +import { Client, ButtonInteraction } from "@client"; export default { id: "deleteInteraction", async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Interaction Message deleted!`); - const messageInteraction = interaction.message.interaction as MessageInteraction; - const message = interaction.message as Message; + const messageInteraction = interaction.message.interaction; + const message = interaction.message; if (messageInteraction != undefined && interaction.user.id != messageInteraction.user.id) return interaction.reply({ diff --git a/src/components/buttons/general/deleteMessage.ts b/src/components/buttons/general/deleteMessage.ts index cdebbbe84..c62e271bb 100644 --- a/src/components/buttons/general/deleteMessage.ts +++ b/src/components/buttons/general/deleteMessage.ts @@ -1,12 +1,12 @@ import { info } from "@helpers/logger"; -import { Client, Message, ButtonInteraction } from "@client"; +import { Client, ButtonInteraction } from "@client"; import { Component } from "@interfaces"; export default { id: "deleteMessage", async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Message deleted!`); - const message = interaction.message as Message; + const message = interaction.message; // if there's no interaction we store the author ID in the footer const authorId = interaction.message.embeds[0].footer?.text.split(" | ")[1]; diff --git a/src/components/buttons/image/comparisonTemplate.ts b/src/components/buttons/image/comparisonTemplate.ts index 2e38b803a..eb2b78ab6 100644 --- a/src/components/buttons/image/comparisonTemplate.ts +++ b/src/components/buttons/image/comparisonTemplate.ts @@ -1,6 +1,6 @@ import { Component } from "@interfaces"; import { info } from "@helpers/logger"; -import { Client, Message, ButtonInteraction, EmbedBuilder } from "@client"; +import { Client, ButtonInteraction, EmbedBuilder } from "@client"; import { magnifyToAttachment } from "@images/magnify"; import { parseDisplay } from "@functions/textureComparison"; import formatName from "@utility/formatName"; @@ -13,7 +13,7 @@ export default { if (client.verbose) console.log(`${info}Comparison template requested!`); await interaction.deferReply({ ephemeral: true }); - const message = interaction.message as Message; + const message = interaction.message; const display = message.embeds[0].footer.text.split(":")[1].trim(); const packs = parseDisplay(display); diff --git a/src/components/buttons/image/magnify.ts b/src/components/buttons/image/magnify.ts index 8927f345e..66621c976 100644 --- a/src/components/buttons/image/magnify.ts +++ b/src/components/buttons/image/magnify.ts @@ -10,7 +10,7 @@ export default { async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Image was magnified!`); - const message = interaction.message as Message; + const message = interaction.message; const url = await getImage(message); if (!url) return imageNotFound(interaction); const attachment = await magnifyToAttachment(url); diff --git a/src/components/buttons/image/palette.ts b/src/components/buttons/image/palette.ts index 7ff1d0d6a..e88e75252 100644 --- a/src/components/buttons/image/palette.ts +++ b/src/components/buttons/image/palette.ts @@ -10,7 +10,7 @@ export default { async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Image palette was requested!`); - const message = interaction.message as Message; + const message = interaction.message; const url = await getImage(message); if (!url) return imageNotFound(interaction); const [file, embed] = await paletteToAttachment(url); diff --git a/src/components/buttons/image/tile.ts b/src/components/buttons/image/tile.ts index 4ef61c0ec..99fecde45 100644 --- a/src/components/buttons/image/tile.ts +++ b/src/components/buttons/image/tile.ts @@ -11,7 +11,7 @@ export default { async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Image was tiled!`); - const message = interaction.message as Message; + const message = interaction.message; const url = await getImage(message); if (!url) return imageNotFound(interaction); const attachment = await tileToAttachment(url); diff --git a/src/components/buttons/poll/pollDelete.ts b/src/components/buttons/poll/pollDelete.ts index e048c4f20..4946f437b 100644 --- a/src/components/buttons/poll/pollDelete.ts +++ b/src/components/buttons/poll/pollDelete.ts @@ -1,15 +1,14 @@ import { Component } from "@interfaces"; import { info } from "@helpers/logger"; -import { Client, Message, ButtonInteraction } from "@client"; -import { MessageInteraction } from "discord.js"; +import { Client, ButtonInteraction } from "@client"; export default { id: "pollDelete", async execute(client: Client, interaction: ButtonInteraction) { if (client.verbose) console.log(`${info}Poll Message deleted!`); - const messageInteraction = interaction.message.interaction as MessageInteraction; - const message = interaction.message as Message; + const messageInteraction = interaction.message.interaction; + const message = interaction.message; const pid = interaction.message.embeds[0].footer.text.split(" | ")[0]; if (messageInteraction != undefined && interaction.user.id != messageInteraction.user.id) diff --git a/src/components/buttons/poll/pollVote.ts b/src/components/buttons/poll/pollVote.ts index f3c86b6df..8604e1884 100644 --- a/src/components/buttons/poll/pollVote.ts +++ b/src/components/buttons/poll/pollVote.ts @@ -1,12 +1,12 @@ import { Component } from "@interfaces"; -import { Client, Message, ButtonInteraction } from "@client"; +import { Client, ButtonInteraction } from "@client"; import { Poll } from "@helpers/poll"; export default { id: "pollVote", async execute(client: Client, interaction: ButtonInteraction) { await interaction.deferUpdate(); - const message = interaction.message as Message; + const message = interaction.message; const embed = message.embeds[0]; // get poll, update it diff --git a/src/components/menus/compareSelect.ts b/src/components/menus/compareSelect.ts index e80f2dbf4..b82256d13 100644 --- a/src/components/menus/compareSelect.ts +++ b/src/components/menus/compareSelect.ts @@ -1,7 +1,7 @@ import { Client, Message, StringSelectMenuInteraction } from "@client"; import { Component } from "@interfaces"; import { info } from "@helpers/logger"; -import { MessageEditOptions, MessageInteraction } from "discord.js"; +import { MessageEditOptions } from "discord.js"; import textureComparison from "@functions/textureComparison"; import { imageTooBig } from "@helpers/warnUser"; @@ -10,8 +10,8 @@ export default { async execute(client: Client, interaction: StringSelectMenuInteraction) { if (client.verbose) console.log(`${info}Texture selected!`); - const messageInteraction = interaction.message.interaction as MessageInteraction; - const message = interaction.message as Message; + const messageInteraction = interaction.message.interaction; + const message = interaction.message; if (interaction.user.id !== messageInteraction.user.id) return interaction.reply({ diff --git a/src/components/menus/cycleSelect.ts b/src/components/menus/cycleSelect.ts index c98b0607f..a412afacb 100644 --- a/src/components/menus/cycleSelect.ts +++ b/src/components/menus/cycleSelect.ts @@ -1,7 +1,6 @@ import { Client, Message, StringSelectMenuInteraction } from "@client"; import { Component } from "@interfaces"; import { info } from "@helpers/logger"; -import { MessageInteraction } from "discord.js"; import { cycleComparison } from "@images/cycle"; export default { @@ -9,8 +8,8 @@ export default { async execute(client: Client, interaction: StringSelectMenuInteraction) { if (client.verbose) console.log(`${info}Texture selected!`); - const messageInteraction = interaction.message.interaction as MessageInteraction; - const message = interaction.message as Message; + const messageInteraction = interaction.message.interaction; + const message = interaction.message; if (interaction.user.id !== messageInteraction.user.id) return interaction.reply({ diff --git a/src/components/menus/textureSelect.ts b/src/components/menus/textureSelect.ts index 338a9ac98..24790bd19 100644 --- a/src/components/menus/textureSelect.ts +++ b/src/components/menus/textureSelect.ts @@ -1,7 +1,6 @@ import { Client, Message, StringSelectMenuInteraction } from "@client"; -import { Component } from "@interfaces"; +import { Component, FaithfulPack } from "@interfaces"; import { info } from "@helpers/logger"; -import { MessageInteraction } from "discord.js"; import { getTexture } from "@functions/getTexture"; import axios from "axios"; @@ -10,8 +9,8 @@ export default { async execute(client: Client, interaction: StringSelectMenuInteraction) { if (client.verbose) console.log(`${info}Texture selected!`); - const messageInteraction = interaction.message.interaction as MessageInteraction; - const message = interaction.message as Message; + const messageInteraction = interaction.message.interaction; + const message = interaction.message; if (interaction.user.id !== messageInteraction.user.id) return interaction.reply({ @@ -27,7 +26,7 @@ export default { const editOptions = await getTexture( interaction, (await axios.get(`${interaction.client.tokens.apiUrl}textures/${id}/all`)).data, - pack, + pack as FaithfulPack, ); if (!editOptions.files) return await interaction.ephemeralReply(editOptions); diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 5b8df477f..c3f99c456 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -1,6 +1,6 @@ import { Event } from "@interfaces"; import { Client, Message, EmbedBuilder } from "@client"; -import { Pack } from "@interfaces"; +import { Submissions } from "@interfaces"; import { colors } from "@utility/colors"; import axios from "axios"; import * as Random from "@utility/random"; @@ -14,7 +14,7 @@ export default { if (message.author.bot) return; - const packs: Pack[] = (await axios.get(`${client.tokens.apiUrl}settings/submission.packs`)) + const packs: Submissions = (await axios.get(`${client.tokens.apiUrl}settings/submission.packs`)) .data; const submissionChannels = Object.values(packs).map((pack) => pack.channels.submit); diff --git a/src/events/slashCommandUsed.ts b/src/events/slashCommandUsed.ts index d51d0bfc6..f3c299a8b 100644 --- a/src/events/slashCommandUsed.ts +++ b/src/events/slashCommandUsed.ts @@ -1,4 +1,4 @@ -import { Pack, SlashCommandI } from "@interfaces"; +import { SlashCommandI, Submissions } from "@interfaces"; import { Collection } from "discord.js"; import { Event } from "@interfaces"; import { Client, ChatInputCommandInteraction, EmbedBuilder } from "@client"; @@ -9,7 +9,7 @@ export default { name: "slashCommandUsed", async execute(client: Client, interaction: ChatInputCommandInteraction) { client.storeAction("slashCommand", interaction); - const packs: Pack[] = (await axios.get(`${client.tokens.apiUrl}settings/submission.packs`)) + const packs: Submissions = (await axios.get(`${client.tokens.apiUrl}settings/submission.packs`)) .data; const submissionChannels = Object.values(packs).map((pack) => pack.channels.submit); diff --git a/src/helpers/functions/getTexture.ts b/src/helpers/functions/getTexture.ts index 38f6e1987..5ce202be4 100644 --- a/src/helpers/functions/getTexture.ts +++ b/src/helpers/functions/getTexture.ts @@ -1,6 +1,6 @@ import { EmbedBuilder } from "@client"; import TokenJson from "@json/tokens.json"; -import { Contributor, GalleryTexture, Tokens } from "@interfaces"; +import { Contributor, FaithfulPack, GalleryTexture, Tokens } from "@interfaces"; import axios from "axios"; import { APIEmbedField, AttachmentBuilder, Interaction } from "discord.js"; import { magnify, magnifyToAttachment } from "@images/magnify"; @@ -17,11 +17,7 @@ import { Image, loadImage } from "@napi-rs/canvas"; * @author Juknum, Evorp, RobertR11 * @returns reply options */ -export async function getTexture( - interaction: Interaction, - texture: Texture, - pack: string, -): Promise { +export async function getTexture(interaction: Interaction, texture: Texture, pack: FaithfulPack) { const tokens: Tokens = TokenJson; const { paths, contributions: allContributions } = texture; const isAnimated = paths.filter((p) => p.mcmeta === true).length !== 0; diff --git a/src/helpers/functions/missing.ts b/src/helpers/functions/missing.ts index 21b18af41..b9f59b55e 100644 --- a/src/helpers/functions/missing.ts +++ b/src/helpers/functions/missing.ts @@ -9,12 +9,13 @@ import { join, normalize } from "path"; import os from "os"; import blacklistedTextures from "@json/blacklisted_textures.json"; import axios from "axios"; +import { FaithfulPack } from "@interfaces"; // return value for the compute function export interface MissingOptions { completion: number; edition: string; - pack: string; + pack: FaithfulPack; version: string; total?: number; } @@ -23,7 +24,7 @@ export type MissingResult = [Buffer, string[], MissingOptions, Buffer?]; export const computeAll = async ( client: Client, - pack: string, + pack: FaithfulPack, version: string, callback: Function, ): Promise => { @@ -38,7 +39,7 @@ export const computeAll = async ( export const computeAndUpdateAll = async ( client: Client, - pack: string, + pack: FaithfulPack, version: string, callback: Function, ): Promise => { @@ -56,7 +57,7 @@ export const computeAndUpdateAll = async ( */ export const computeAndUpdate = async ( client: Client, - pack: string, + pack: FaithfulPack, edition: string, version: string, callback: Function, @@ -94,7 +95,7 @@ export const computeAndUpdate = async ( */ export const compute = async ( client: Client, - pack: string, + pack: FaithfulPack, edition: string, version: string, callback: Function, diff --git a/src/helpers/functions/textureComparison.ts b/src/helpers/functions/textureComparison.ts index cbf718a09..4e076ef22 100644 --- a/src/helpers/functions/textureComparison.ts +++ b/src/helpers/functions/textureComparison.ts @@ -3,7 +3,7 @@ import { magnifyToAttachment } from "@images/magnify"; import { Image, loadImage } from "@napi-rs/canvas"; import { Client, EmbedBuilder } from "@client"; import { addPathsToEmbed } from "@functions/getTexture"; -import { GalleryTexture } from "@interfaces"; +import { AnyPack, GalleryTexture } from "@interfaces"; import axios from "axios"; import { ActionRowBuilder, ButtonBuilder } from "discord.js"; import { template } from "@utility/buttons"; @@ -15,7 +15,7 @@ import { template } from "@utility/buttons"; * @returns selected packs */ export function parseDisplay(display: string) { - const PACKS = [ + const PACKS: AnyPack[][] = [ ["default", "faithful_32x", "faithful_64x"], ["default", "classic_faithful_32x", "classic_faithful_64x"], ["progart", "classic_faithful_32x_progart"], @@ -45,7 +45,7 @@ export default async function textureComparison( client: Client, id: string, display: string = "all", -): Promise { +) { const result: GalleryTexture = ( await axios.get(`${client.tokens.apiUrl}gallery/modal/${id}/latest`) ).data; diff --git a/src/helpers/getImage.ts b/src/helpers/getImage.ts index 0d6696da6..f6206c450 100644 --- a/src/helpers/getImage.ts +++ b/src/helpers/getImage.ts @@ -12,8 +12,7 @@ import { warnUser } from "./warnUser"; // remove stupid discord metadata (idk why they even added it) export const removeMetadata = (url: string) => url.split("?")[0]; -export const isImage = (url: string) => - url && /(png|jpg|jpeg|webp)$/g.test(removeMetadata(url)); +export const isImage = (url: string) => url && /(png|jpg|jpeg|webp)$/g.test(removeMetadata(url)); // taken from loadImage(); export type ImageSource = string | URL | Buffer | ArrayBufferLike | Uint8Array | Image | Readable; diff --git a/src/helpers/images/cycle.ts b/src/helpers/images/cycle.ts index ec3884772..e74fe69af 100644 --- a/src/helpers/images/cycle.ts +++ b/src/helpers/images/cycle.ts @@ -13,32 +13,30 @@ import { Texture } from "@interfaces"; * @param framerate framerate of the gif * @returns gif as a message attachment */ -export async function imagesToGIF(images: Image[], framerate: number): Promise { +export async function imagesToGIF(images: Image[], framerate = 1) { const biggestImage = images.reduce((a, e) => (a.width > e.width ? a : e), { width: 0, height: 0, }); // magnify all images to an equal size - let finalWidth: number; - let finalHeight: number; const maxWidth = 1024; const maxHeight = 1024; const maxAspect = maxWidth / maxHeight; const aspect = biggestImage.width / biggestImage.height; - if (maxAspect < aspect) { - finalWidth = maxWidth; - finalHeight = maxWidth / aspect; - } else { - finalHeight = maxHeight; - finalWidth = maxWidth * aspect; - } + + let finalWidth = maxWidth; + let finalHeight = maxHeight; + + if (maxAspect < aspect) finalHeight = maxWidth / aspect; + else finalWidth = maxWidth * aspect; const encoder = new GIFEncoder(finalWidth, finalHeight); encoder.start(); encoder.setTransparent(true); + for (const image of images) { - // converting the Image() object to a Canvas() object + // convert Image to a Canvas so the encoder can accept it const canvas = createCanvas(finalWidth, finalHeight); const ctx = canvas.getContext("2d"); ctx.imageSmoothingEnabled = false; @@ -62,10 +60,10 @@ export async function imagesToGIF(images: Image[], framerate: number): Promise { + framerate?: number, +) { const result: Texture = (await axios.get(`${client.tokens.apiUrl}textures/${id}/all`)).data; let packText: string; diff --git a/src/helpers/images/multiply.ts b/src/helpers/images/multiply.ts index 1a660ffa3..eeb5700da 100644 --- a/src/helpers/images/multiply.ts +++ b/src/helpers/images/multiply.ts @@ -31,13 +31,11 @@ export const mcColors = { }; export const mcColorsOptions: { name: string; value: string }[] = Object.keys(mcColors).map( - (name) => { - //a cheeky regex for formatting - return { - name: name.replace(/([a-z])([A-Z])/g, "$1 $2"), - value: mcColors[name as keyof typeof mcColors], - }; - }, + // a cheeky regex for formatting + (name: keyof typeof mcColors) => ({ + name: name.replace(/([a-z])([A-Z])/g, "$1 $2"), + value: mcColors[name], + }), ); /** diff --git a/src/helpers/poll.ts b/src/helpers/poll.ts index c4f53ccc6..abb64da7e 100644 --- a/src/helpers/poll.ts +++ b/src/helpers/poll.ts @@ -132,9 +132,10 @@ export class Poll extends TimedEmbed { embed.setTitle(options.question); embed.setFooter({ text: `${this.id} | Use /poll to make a poll!` }); embed.addFields( - options.answersArr.map((answer: string) => { - return { name: `${answer}`, value: `No votes yet.` }; - }), + options.answersArr.map((answer: string) => ({ + name: `${answer}`, + value: `No votes yet.`, + })), ); // votes options setup diff --git a/src/helpers/utility/formatName.ts b/src/helpers/utility/formatName.ts index 58d497969..1dc28fece 100644 --- a/src/helpers/utility/formatName.ts +++ b/src/helpers/utility/formatName.ts @@ -1,3 +1,5 @@ +import { AnyPack } from "@interfaces"; + /** * Format a pack ID into a displayable name and icon * @author Evorp @@ -6,39 +8,39 @@ * @todo migrate this to somewhere better for extensibility (api probably) * @returns formatted string and icon in that order */ -export default function formatName(pack: string, size = "512"): [string, string] { - let strPack: string; - let strIconURL = `https://database.faithfulpack.net/images/branding/logos/transparent/${size}/`; +export default function formatName(pack: AnyPack, size = "512"): [string, string] { + let packName: string; + let iconURL = `https://database.faithfulpack.net/images/branding/logos/transparent/${size}/`; switch (pack) { case "faithful_32x": - strPack = "Faithful 32x"; - strIconURL += "f32_logo.png"; + packName = "Faithful 32x"; + iconURL += "f32_logo.png"; break; case "faithful_64x": - strPack = "Faithful 64x"; - strIconURL += "f64_logo.png"; + packName = "Faithful 64x"; + iconURL += "f64_logo.png"; break; case "classic_faithful_32x": - strPack = "Classic Faithful 32x Jappa"; - strIconURL += "cf32_logo.png"; + packName = "Classic Faithful 32x Jappa"; + iconURL += "cf32_logo.png"; break; case "classic_faithful_32x_progart": - strPack = "Classic Faithful 32x Programmer Art"; - strIconURL += "cf32pa_logo.png"; + packName = "Classic Faithful 32x Programmer Art"; + iconURL += "cf32pa_logo.png"; break; case "classic_faithful_64x": - strPack = "Classic Faithful 64x"; - strIconURL += "cf64_logo.png"; + packName = "Classic Faithful 64x"; + iconURL += "cf64_logo.png"; break; case "progart": - strPack = "Default Programmer Art"; + packName = "Default Programmer Art"; // have to redefine since root directory is different - strIconURL = `https://database.faithfulpack.net/images/bot/progart.png?w=${size}`; + iconURL = `https://database.faithfulpack.net/images/bot/progart.png?w=${size}`; break; default: - strPack = "Default Jappa"; - strIconURL = `https://database.faithfulpack.net/images/bot/default.png?w=${size}`; + packName = "Default Jappa"; + iconURL = `https://database.faithfulpack.net/images/bot/default.png?w=${size}`; break; } - return [strPack, strIconURL]; + return [packName, iconURL]; } diff --git a/src/interfaces/firestorm.ts b/src/interfaces/firestorm.ts index d734b3751..ba1f9081a 100644 --- a/src/interfaces/firestorm.ts +++ b/src/interfaces/firestorm.ts @@ -1,18 +1,32 @@ +export type Edition = "java" | "bedrock"; + +export type FaithfulPack = + | "faithful_32x" + | "faithful_64x" + | "classic_faithful_32x" + | "classic_faithful_32x_progart" + | "classic_faithful_64x"; + +export type VanillaPack = "default" | "progart"; + +export type AnyPack = FaithfulPack | VanillaPack; + export interface Contribution { id: string; date: number; // unix timestamp texture: string; // texture ID resolution: number; // texture resolution - pack: - | "faithful_64x" - | "faithful_32x" - | "classic_faithful_32x" - | "classic_faithful_64x" - | "classic_faithful_32x_progart" - | "classic_faithful_64x_progart"; + pack: FaithfulPack; authors: string[]; } +export interface Contributor { + id: string; + contributions: number; + username?: string; + uuid?: string; +} + export interface Path { id: string; use: string; // use ID @@ -24,7 +38,7 @@ export interface Path { export interface Use { id: string; name: string; - edition: "java" | "bedrock"; + edition: Edition; } // when you don't add the "all" flag when searching on the API @@ -42,13 +56,7 @@ export interface Texture extends BaseTexture { // used for comparison loader export interface GalleryTexture extends Omit { + // texture properties are moved into their own object texture: BaseTexture; urls: [string, string]; } - -export interface Contributor { - id: string; - contributions: number; - username?: string; - uuid?: string; -} diff --git a/src/interfaces/submission.ts b/src/interfaces/submission.ts index bce1d664c..8b893e810 100644 --- a/src/interfaces/submission.ts +++ b/src/interfaces/submission.ts @@ -1,20 +1,16 @@ +import { Edition } from "./firestorm"; + // settings.submission.packs -export type Submissions = Record; +export type Submissions = Record; // one specific pack instance -export interface Pack { +export interface SubmissionPack { channels: Channels; council_enabled: boolean; time_to_results: number; time_to_council?: number; // not used if council disabled contributor_role?: string; - github: { - // java and bedrock - [edition: string]: { - repo: string; - org: string; - }; - }; + github: Record; } // just the channels