Skip to content

Commit

Permalink
chore(deps): update dependency @nhcarrigan/eslint-config to v5.1.0 (#754
Browse files Browse the repository at this point in the history
)

* chore(deps): update dependency @nhcarrigan/eslint-config to v5.1.0

* feat: resolve linter issues

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Naomi Carrigan <[email protected]>
  • Loading branch information
renovate[bot] and naomi-lgbt authored Jan 7, 2025
1 parent 4582449 commit 4a560ab
Show file tree
Hide file tree
Showing 39 changed files with 1,135 additions and 832 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"winston": "3.17.0"
},
"devDependencies": {
"@nhcarrigan/eslint-config": "5.0.0",
"@nhcarrigan/eslint-config": "5.1.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/diff": "6.0.0",
"@types/node": "22.10.5",
Expand Down
1,293 changes: 737 additions & 556 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/commands/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const author: Command = {
}

const ourId = "65dc2b7cbb4eb0cd565b4463";
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const query = gql`
query getMember {
user(username: "Koded001") {
Expand All @@ -68,8 +67,7 @@ export const author: Command = {
}
`;
const data
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/consistent-type-assertions
= await request("https://gql.hashnode.com", query) as HashnodeUser;
= await request<HashnodeUser>("https://gql.hashnode.com", query);

if (!data.user) {
await interaction.editReply({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { Command } from "../interfaces/command.js";
import type { Subcommand } from "../interfaces/subcommand.js";

const handlers: Record<string, Subcommand> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord command names can't use uppercase characters.
"code-of-conduct": handleCodeOfConduct,
"contribute": handleContribute,
"forum": handleForum,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import type { Command } from "../interfaces/command.js";
import type { Subcommand } from "../interfaces/subcommand.js";

const handlers: Record<string, Subcommand> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord command names can't use uppercase characters.
"add-labels": handleAddLabels,
"close": handleClose,
"comment": handleComment,
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord command names can't use uppercase characters.
"sync-labels": handleSyncLabels,
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/subcommands/community/handleForum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const handleForum: Subcommand = {
try {
await interaction.deferReply();
const data = await fetch("https://forum.freecodecamp.org/latest.json");
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- It kills me that .json() doesn't take a generic.
const parsed = (await data.json()) as ForumData;
const topics = parsed.topic_list.topics.slice(0, 5);
const forumEmbed = new EmbedBuilder().
Expand Down
157 changes: 93 additions & 64 deletions src/commands/subcommands/community/handleLeaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,93 @@ import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
type ButtonInteraction,
type ChatInputCommandInteraction,
type ComponentType,
} from "discord.js";
import { generateLeaderboardImage }
from "../../../modules/generateProfileImage.js";
import { errorHandler } from "../../../utils/errorHandler.js";
import type { ExtendedClient } from "../../../interfaces/extendedClient.js";
import type { Subcommand } from "../../../interfaces/subcommand.js";
import type { levels } from "@prisma/client";

const handleClickEnd = async(
pageBack: ButtonBuilder,
pageForward: ButtonBuilder,
interaction: ChatInputCommandInteraction,
): Promise<void> => {
pageBack.setDisabled(true);
pageForward.setDisabled(true);
await interaction.editReply({
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
pageBack,
pageForward,
),
],
});
};

const handleClick = async(
camperChan: ExtendedClient,
parameters: {
click: ButtonInteraction;
interaction: ChatInputCommandInteraction;
pageBack: ButtonBuilder;
pageForward: ButtonBuilder;
pagination: { page: number; lastPage: number; itemsForPage: number };
mapped: Array<levels & { index: number }>;
},
): Promise<void> => {
const { click, interaction, pageBack, pageForward, pagination, mapped }
= parameters;
let { page } = pagination;
const { lastPage, itemsForPage } = pagination;
await click.deferUpdate();
if (click.customId === "prev") {
page = page - 1;
}
if (click.customId === "next") {
page = page + 1;
}

if (page <= 1) {
pageBack.setDisabled(true);
} else {
pageBack.setDisabled(false);
}

if (page >= lastPage) {
pageForward.setDisabled(true);
} else {
pageForward.setDisabled(false);
}

const updatedAttachment = await generateLeaderboardImage(
camperChan,
mapped.slice(itemsForPage - 10, itemsForPage),
);

if (!updatedAttachment) {
await interaction.editReply({
components: [],
content: "Failed to load leaderboard image.",
files: [],
});
return;
}

await interaction.editReply({
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
pageBack,
pageForward,
),
],
files: [ updatedAttachment ],
});
};

export const handleLeaderboard: Subcommand = {
execute: async(camperChan, interaction) => {
Expand All @@ -27,7 +108,7 @@ export const handleLeaderboard: Subcommand = {
};
});

let page = 1;
const page = 1;
const lastPage = Math.ceil(mapped.length / 10);

const pageBack = new ButtonBuilder().
Expand All @@ -39,13 +120,6 @@ export const handleLeaderboard: Subcommand = {
setCustomId("next").
setLabel("▶").
setStyle(ButtonStyle.Primary);

if (page <= 1) {
pageBack.setDisabled(true);
} else {
pageBack.setDisabled(false);
}

if (page >= lastPage) {
pageForward.setDisabled(true);
} else {
Expand Down Expand Up @@ -87,65 +161,20 @@ export const handleLeaderboard: Subcommand = {
time: 300_000,
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
clickyClick.on("collect", async(click) => {
await click.deferUpdate();
if (click.customId === "prev") {
page = page - 1;
}
if (click.customId === "next") {
page = page + 1;
}

if (page <= 1) {
pageBack.setDisabled(true);
} else {
pageBack.setDisabled(false);
}

if (page >= lastPage) {
pageForward.setDisabled(true);
} else {
pageForward.setDisabled(false);
}

const updatedAttachment = await generateLeaderboardImage(
camperChan,
mapped.slice(itemsForPage - 10, itemsForPage),
);

if (!updatedAttachment) {
await interaction.editReply({
components: [],
content: "Failed to load leaderboard image.",
files: [],
});
return;
}

await interaction.editReply({
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
pageBack,
pageForward,
),
],
files: [ updatedAttachment ],
clickyClick.on("collect", (click) => {
const pagination = { itemsForPage, lastPage, page };
void handleClick(camperChan, {
click,
interaction,
mapped,
pageBack,
pageForward,
pagination,
});
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
clickyClick.on("end", async() => {
pageBack.setDisabled(true);
pageForward.setDisabled(true);
await interaction.editReply({
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
pageBack,
pageForward,
),
],
});
clickyClick.on("end", () => {
void handleClickEnd(pageBack, pageForward, interaction);
});
} catch (error) {
await errorHandler(camperChan, "leaderboard subcommand", error);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/subcommands/github/handleAddLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const handleAddLabels: Subcommand = {

const response = await camperChan.octokit.rest.issues.listLabelsForRepo({
owner: "freeCodeCamp",
// eslint-disable-next-line @typescript-eslint/naming-convention, camelcase
// eslint-disable-next-line @typescript-eslint/naming-convention, camelcase -- Github API name.
per_page: 100,
repo: repo,
});
Expand Down Expand Up @@ -44,7 +44,7 @@ export const handleAddLabels: Subcommand = {
}

await camperChan.octokit.rest.issues.addLabels({
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
labels: labelNames,
owner: "freeCodeCamp",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/subcommands/github/handleClose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const handleClose: Subcommand = {
const isSpam = interaction.options.getBoolean("spam") ?? false;

const data = await camperChan.octokit.rest.issues.get({
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
owner: "freeCodeCamp",
repo: repo,
Expand All @@ -47,21 +47,21 @@ export const handleClose: Subcommand = {
const isPull = Boolean(data.data.pull_request);
await camperChan.octokit.rest.issues.createComment({
body: commentBody(isPull, comment),
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
owner: "freeCodeCamp",
repo: repo,
});
await camperChan.octokit.rest.issues.update({
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
owner: "freeCodeCamp",
repo: repo,
state: "closed",
});
if (isPull && isSpam) {
await camperChan.octokit.rest.issues.addLabels({
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
labels: [ "spam" ],
owner: "freeCodeCamp",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/subcommands/github/handleComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const handleComment: Subcommand = {

const comment = await camperChan.octokit.rest.issues.createComment({
body: message,
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: pull,
owner: "freeCodeCamp",
repo: repo,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/subcommands/github/handleSyncLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const handleSyncLabels: Subcommand = {
});

await camperChan.octokit.rest.issues.setLabels({
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github API name.
issue_number: number,
labels: labelNames,
owner: "freeCodeCamp",
Expand Down
10 changes: 6 additions & 4 deletions src/commands/subcommands/moderation/handleBan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export const handleBan: Subcommand = {

const sentNotice = await sendModerationDm(
camperChan,
"ban",
target,
guild.name,
reason,
{
action: "ban",
guildName: guild.name,
reason: customSubstring(reason, 1000),
user: target,
},
);

await targetMember.ban({
Expand Down
10 changes: 6 additions & 4 deletions src/commands/subcommands/moderation/handleKick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export const handleKick: Subcommand = {

const sentNotice = await sendModerationDm(
camperChan,
"kick",
target,
guild.name,
reason,
{
action: "kick",
guildName: guild.name,
reason: customSubstring(reason, 1000),
user: target,
},
);

await targetMember.kick(customSubstring(reason, 1000));
Expand Down
10 changes: 6 additions & 4 deletions src/commands/subcommands/moderation/handleMute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ export const handleMute: Subcommand = {

const sentNotice = await sendModerationDm(
camperChan,
"mute",
target,
guild.name,
reason,
{
action: "mute",
guildName: guild.name,
reason: customSubstring(reason, 1000),
user: target,
},
);

await targetMember.timeout(durationMilliseconds, reason);
Expand Down
10 changes: 6 additions & 4 deletions src/commands/subcommands/moderation/handleUnmute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export const handleUnmute: Subcommand = {

const sentNotice = await sendModerationDm(
camperChan,
"unmute",
target,
guild.name,
reason,
{
action: "unmute",
guildName: guild.name,
reason: customSubstring(reason, 1000),
user: target,
},
);

const muteEmbed = new EmbedBuilder();
Expand Down
Loading

0 comments on commit 4a560ab

Please sign in to comment.