Skip to content

Commit

Permalink
stricter code quality, update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jan 5, 2025
1 parent a4eb0d1 commit 4773d9f
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 60 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"prettier": "prettier \"{,!(node_modules)/**/}*.ts\" --config .prettierrc --write"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"nodemon": "^3.1.9",
"prettier": "^3.4.2"
},
"dependencies": {
"@napi-rs/canvas": "^0.1.65",
"@octokit/rest": "^20.1.1",
"axios": "^1.7.9",
"cron": "^3.3.1",
"cron": "^3.3.2",
"discord.js": "^14.16.3",
"dotenv": "^16.4.7",
"gif-encoder-2": "^1.0.5",
Expand Down
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/commands/bot/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default {
.setRequired(true),
),
async execute(interaction) {
const type = interaction.options.getString("type");
const type = interaction.options.getString("type") as keyof typeof feedbackFormat;
const modal = new ModalBuilder().setCustomId(`${type}Ticket`).setTitle(`New ${type} issue`);

modal.addComponents(
// every modal input needs to be in a new action row (blame djs)
...feedbackFormat[type].map((textInput: TextInputBuilder) =>
...feedbackFormat[type].map((textInput) =>
new ActionRowBuilder<TextInputBuilder>().addComponents(textInput),
),
);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/bot/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder().setName("ping").setDescription(strings.command.description.ping),
async execute(interaction) {
const quotes = (
const quotes: string[] = (
await axios.get(
`https://raw.githubusercontent.com/Faithful-Resource-Pack/CompliBot/main/json/quotes.json`,
)
Expand All @@ -27,7 +27,7 @@ export default {

const embed = new EmbedBuilder()
.setTitle("Pong!")
.setDescription(`_${quote.replace("%YEAR%", new Date().getFullYear() + 2)}_`)
.setDescription(`_${quote.replace("%YEAR%", String(new Date().getFullYear() + 2))}_`)
.setColor(settings.colors.blue)
.addFields(
{ name: "Bot Latency", value: `${botPing}ms`, inline: true },
Expand Down
2 changes: 1 addition & 1 deletion src/commands/bot/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
.setDescription("What activity the bot is doing (e.g. playing, streaming)")
.addChoices(
...Object.values(ActivityType)
.filter((x) => typeof x == "string")
.filter((x) => typeof x === "string")
.map((i) => ({ name: i, value: i })),
)
.setRequired(true),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/developer/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
return warnUser(interaction, strings.command.no_permission);
await interaction.deferReply({ ephemeral: true });

const clean = async (text) => {
const clean = async (text: any) => {
if (text && text.constructor.name === "Promise") text = await text;
if (typeof text !== "string") text = require("util").inspect(text, { depth: 1 });

Expand All @@ -41,7 +41,7 @@ export default {
// ----

const code = interaction.options.getString("code", true);
let evaluated;
let evaluated: any;
try {
evaluated = await eval(
`(async () => { try { return await (async () => {${
Expand Down
1 change: 0 additions & 1 deletion src/commands/developer/say.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default {
.addStringOption((option) =>
option.setName("message").setDescription("What should the bot say?").setRequired(true),
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setDMPermission(false),
async execute(interaction) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/submission/autopush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default {
const choice = interaction.options.getString("pack", true);
const addContributions = interaction.options.getBoolean("contributions", false) ?? true;

if (choice == "all" && !process.env.DEVELOPERS.includes(interaction.user.id))
if (choice === "all" && !process.env.DEVELOPERS.includes(interaction.user.id))
return warnUser(interaction, strings.command.no_permission);

const packs = choice == "all" ? Object.values(submissions) : [submissions[choice]];
const packs = choice === "all" ? Object.values(submissions) : [submissions[choice]];

const infoEmbed = new EmbedBuilder()
.setDescription("This can take some time, please wait...")
Expand Down
4 changes: 2 additions & 2 deletions src/commands/submission/channelpush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export default {
const submissions: PackFile = require("@resources/packs.json");
const choice = interaction.options.getString("pack", true);
const delay = interaction.options.getInteger("delay", false);
if (choice == "all" && !process.env.DEVELOPERS.includes(interaction.user.id))
if (choice === "all" && !process.env.DEVELOPERS.includes(interaction.user.id))
return warnUser(interaction, strings.command.no_permission);

const packs = choice == "all" ? Object.values(submissions) : [submissions[choice]];
const packs = choice === "all" ? Object.values(submissions) : [submissions[choice]];

await interaction.deferReply();

Expand Down
2 changes: 1 addition & 1 deletion src/events/buttonUsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
message.deletable &&
(!original ||
hasPermission(interaction.member as GuildMember, "moderator") ||
original.id == interaction.user.id)
original.id === interaction.user.id)
)
return message.delete();

Expand Down
2 changes: 1 addition & 1 deletion src/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
/**
* TEXTURE SUBMISSION
*/
if (Object.values(packs).some((pack) => pack.submission.channels.submit == message.channel.id))
if (Object.values(packs).some((pack) => pack.submission.channels.submit === message.channel.id))
return submitTexture(message);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/functions/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function handleError(client: Client, error: any, type: string) {
return console.error(consoleDescription);

// silence EPROTO errors
if (error.code == "EPROTO") return console.error(consoleDescription);
if (error.code === "EPROTO") return console.error(consoleDescription);

// DO NOT DELETE THIS CATCH, IT AVOIDS INFINITE LOOP IF THIS PROMISE REJECTS
devLogger(client, embedDescription, { title: type, codeBlocks }).catch(console.error);
Expand Down
2 changes: 1 addition & 1 deletion src/functions/images/magnify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function magnify(origin: ImageSource, isAnimation = false) {
const surface = isAnimation ? input.width * 16 : input.width * input.height;

let factor = 64;
if (surface == 256) factor = 32;
if (surface === 256) factor = 32;
if (surface > 256) factor = 16;
if (surface > 1024) factor = 8;
if (surface > 4096) factor = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/images/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default async function palette(interaction: AnyInteraction, origin: Image

// create palette links, 9 max per link
// make arrays of hex arrays
const paletteGroups = [];
const paletteGroups: string[][] = [];
for (let i = 0; i < colors.length; ++i) {
if (i % COLORS_PER_PALETTE === 0) paletteGroups.push([]);
paletteGroups.at(-1).push(colors[i].replace("#", ""));
Expand Down
4 changes: 2 additions & 2 deletions src/functions/images/stitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { createCanvas, Image } from "@napi-rs/canvas";
* @returns stitched texture and the gap length added
*/
export default async function stitch(images: Image[], gap?: number): Promise<[Buffer, number]> {
const biggestImage = images.reduce((a, e) => (a.width > e.width ? a : e), {
const biggestImage = images.reduce((best, cur) => (best.width > cur.width ? best : cur), {
width: 0,
height: 0,
});

if (gap == null || gap == undefined) {
if (gap === null || gap === undefined) {
// the gap should be the size of one 16x "pixel"
gap = 1;
if (biggestImage.width > 16) gap = 2;
Expand Down
7 changes: 4 additions & 3 deletions src/functions/submission/handleResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ export async function downloadTexture(
return;
}

const imageFile = (await axios.get(texture.url, { responseType: "arraybuffer" })).data;
const imageFile = (await axios.get<Buffer>(texture.url, { responseType: "arraybuffer" })).data;

let textureInfo: Texture;
try {
textureInfo = (await axios.get(`${process.env.API_URL}textures/${texture.id}/all`)).data;
textureInfo = (await axios.get<Texture>(`${process.env.API_URL}textures/${texture.id}/all`))
.data;
} catch {
// handles if texture gets deleted in the db between submission and results (merged, obsolete, etc)
if (DEBUG) console.error(`Could not find texture for ID: ${texture.id}`);
Expand All @@ -108,7 +109,7 @@ export async function downloadTexture(

// add the image to all its versions and paths
for (const use of textureInfo.uses) {
const paths = textureInfo.paths.filter((path) => path.use == use.id);
const paths = textureInfo.paths.filter((path) => path.use === use.id);

// need to redefine pack folder every time since java/bedrock are different folders
const packFolder = pack.github[use.edition]?.repo;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/submission/makeEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default async function makeEmbed(
* @returns usable embed field data
*/
export function addPathsToEmbed(texture: Texture): APIEmbedField[] {
const groupedPaths: Partial<Record<MinecraftEdition, string[]>> = texture.uses.reduce(
const groupedPaths = texture.uses.reduce<Partial<Record<MinecraftEdition, string[]>>>(
(acc, use) => {
const paths = texture.paths
.filter((el) => el.use === use.id)
Expand Down
6 changes: 3 additions & 3 deletions src/functions/submission/reactionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function reactionMenu(openReaction: MessageReaction, user:
const submissionAuthorID = message.embeds[0].fields[0].value.split("\n")[0].replace(/\D+/g, "");

// if you don't check to close tray first, the bot won't listen for reactions upon restart
if (openReaction.emoji.id == settings.emojis.see_less) return closeTray(message, allReactions);
if (openReaction.emoji.id === settings.emojis.see_less) return closeTray(message, allReactions);

if (!canOpenTray(message, openReaction, member, submissionAuthorID)) return;

Expand Down Expand Up @@ -69,7 +69,7 @@ export default async function reactionMenu(openReaction: MessageReaction, user:
const reactor = Array.from(actionReaction.users.cache.values()).find((user) => !user.bot);

if (
actionReaction.emoji.id == settings.emojis.delete &&
actionReaction.emoji.id === settings.emojis.delete &&
// only admins can delete messages (prevent abuse)
(reactor.id === submissionAuthorID || hasPermission(member, "administrator")) &&
message.deletable
Expand Down Expand Up @@ -137,7 +137,7 @@ function filterReactions(message: Message, member: GuildMember, allReactions: st
const packs: PackFile = require("@resources/packs.json");

// if the submission is in council remove delete reaction (avoid misclick)
if (Object.values(packs).some((pack) => pack.submission.channels.council == message.channel.id))
if (Object.values(packs).some((pack) => pack.submission.channels.council === message.channel.id))
allReactions = allReactions.filter((emoji) => emoji !== settings.emojis.delete);

// remove instapass/invalid if just the author is reacting or if submission is no longer pending
Expand Down
4 changes: 2 additions & 2 deletions src/functions/submission/submitTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function submitTexture(message: Message<true>) {

let results: Texture[] = [];
try {
results = (await axios.get(`${process.env.API_URL}textures/${search}/all`)).data;
results = (await axios.get<Texture[]>(`${process.env.API_URL}textures/${search}/all`)).data;
} catch {
await cancelSubmission(message, strings.submission.does_not_exist + "\n" + search);
continue;
Expand All @@ -68,7 +68,7 @@ export default async function submitTexture(message: Message<true>) {
continue;
}

if (results.length == 1) {
if (results.length === 1) {
await makeEmbed(message, results[0], attachment, param);
continue;
}
Expand Down
15 changes: 9 additions & 6 deletions src/functions/submission/utility/choiceEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Message,
SelectMenuComponentOptionData,
StringSelectMenuInteraction,
ComponentType,
} from "discord.js";
import { hasPermission } from "@helpers/permissions";
import axios from "axios";
Expand Down Expand Up @@ -60,15 +61,17 @@ export default async function choiceEmbed(
const choiceMessage = await message.reply({ embeds: [embed], components: components });
await addDeleteButton(choiceMessage);

// typed as any since we know it's a string select menu but discord.js doesn't
const filter: any = (interaction: StringSelectMenuInteraction) =>
const filter = (interaction: StringSelectMenuInteraction) =>
// format is choiceEmbed_<ROWNUMBER> (needs unique ids)
interaction.customId.startsWith("choiceEmbed") &&
interaction.message.id == choiceMessage.id &&
interaction.message.id === choiceMessage.id &&
// admins can interact with choice embeds always
(interaction.user.id == message.author.id || hasPermission(message.member, "administrator"));
(interaction.user.id === message.author.id || hasPermission(message.member, "administrator"));

const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
const collector = message.channel.createMessageComponentCollector<ComponentType.StringSelect>({
filter,
time: 60000,
});

collector.once("collect", async (interaction: StringSelectMenuInteraction) => {
if (!message.deletable) {
Expand All @@ -86,7 +89,7 @@ export default async function choiceEmbed(
authors: await getAuthors(message),
};

const texture: Texture = (await axios.get(`${process.env.API_URL}textures/${id}/all`)).data;
const texture = (await axios.get<Texture>(`${process.env.API_URL}textures/${id}/all`)).data;
if (choiceMessage.deletable) await choiceMessage.delete();

return makeEmbed(message, texture, attachments[index], param);
Expand Down
Loading

0 comments on commit 4773d9f

Please sign in to comment.