Skip to content

Commit

Permalink
pack types and remove unnecessary casts
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 28, 2023
1 parent a4142c6 commit 6deb49d
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 130 deletions.
7 changes: 4 additions & 3 deletions src/commands/developer/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
7 changes: 4 additions & 3 deletions src/commands/faithful/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/commands/faithful/missing.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
)
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/commands/faithful/texture.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/commands/fun/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
7 changes: 3 additions & 4 deletions src/components/buttons/general/deleteInteraction.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 2 additions & 2 deletions src/components/buttons/general/deleteMessage.ts
Original file line number Diff line number Diff line change
@@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/components/buttons/image/comparisonTemplate.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/image/magnify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/image/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/image/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/components/buttons/poll/pollDelete.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/components/buttons/poll/pollVote.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/components/menus/compareSelect.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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({
Expand Down
5 changes: 2 additions & 3 deletions src/components/menus/cycleSelect.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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 {
id: "cycleSelect",
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({
Expand Down
9 changes: 4 additions & 5 deletions src/components/menus/textureSelect.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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({
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/events/slashCommandUsed.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions src/helpers/functions/getTexture.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<any> {
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;
Expand Down
11 changes: 6 additions & 5 deletions src/helpers/functions/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<MissingResult[]> => {
Expand All @@ -38,7 +39,7 @@ export const computeAll = async (

export const computeAndUpdateAll = async (
client: Client,
pack: string,
pack: FaithfulPack,
version: string,
callback: Function,
): Promise<MissingResult[]> => {
Expand All @@ -56,7 +57,7 @@ export const computeAndUpdateAll = async (
*/
export const computeAndUpdate = async (
client: Client,
pack: string,
pack: FaithfulPack,
edition: string,
version: string,
callback: Function,
Expand Down Expand Up @@ -94,7 +95,7 @@ export const computeAndUpdate = async (
*/
export const compute = async (
client: Client,
pack: string,
pack: FaithfulPack,
edition: string,
version: string,
callback: Function,
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/functions/textureComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"],
Expand Down Expand Up @@ -45,7 +45,7 @@ export default async function textureComparison(
client: Client,
id: string,
display: string = "all",
): Promise<any> {
) {
const result: GalleryTexture = (
await axios.get(`${client.tokens.apiUrl}gallery/modal/${id}/latest`)
).data;
Expand Down
Loading

0 comments on commit 6deb49d

Please sign in to comment.