Skip to content

Commit

Permalink
TypeScript Rewrite (#15)
Browse files Browse the repository at this point in the history
The bot has already been pretty well typed with JSDoc this entire time, but having entire files of pure JSDoc types felt a bit stupid and the lack of any real build step made stuff like ESM a lot more difficult. Thus, I've basically just translated over the existing JSDoc types to a full TypeScript rewrite and fixed some random type-related bugs in the process that strict checking brings.
  • Loading branch information
3vorp authored Aug 4, 2024
1 parent a264662 commit 1a7292b
Show file tree
Hide file tree
Showing 78 changed files with 1,604 additions and 1,346 deletions.
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

18 changes: 11 additions & 7 deletions commands/bot/feedback.js → commands/bot/feedback.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const strings = require("@resources/strings.json");
import strings from "@resources/strings.json";

const {
import {
ActionRowBuilder,
ModalBuilder,
SlashCommandBuilder,
TextInputBuilder,
TextInputStyle,
} = require("discord.js");
} from "discord.js";

import type { Command } from "@interfaces/discord";

// I'm sorry...
const feedbackFormat = {
Expand Down Expand Up @@ -53,8 +55,8 @@ const feedbackFormat = {
.setRequired(false),
],
};
/** @type {import("@helpers/jsdoc").Command} */
module.exports = {

export default {
data: new SlashCommandBuilder()
.setName("feedback")
.setDescription(strings.command.description.feedback)
Expand All @@ -74,9 +76,11 @@ module.exports = {

modal.addComponents(
// every modal input needs to be in a new action row (blame djs)
...feedbackFormat[type].map((textInput) => new ActionRowBuilder().addComponents(textInput)),
...feedbackFormat[type].map((textInput: TextInputBuilder) =>
new ActionRowBuilder<TextInputBuilder>().addComponents(textInput),
),
);

await interaction.showModal(modal);
},
};
} as Command;
16 changes: 8 additions & 8 deletions commands/bot/ping.js → commands/bot/ping.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const addDeleteButton = require("@helpers/addDeleteButton");
import addDeleteButton from "@helpers/addDeleteButton";

const axios = require("axios").default;
const { EmbedBuilder, SlashCommandBuilder } = require("discord.js");
import axios from "axios";
import { EmbedBuilder, SlashCommandBuilder } from "discord.js";
import type { Command } from "@interfaces/discord";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
export default {
data: new SlashCommandBuilder().setName("ping").setDescription(strings.command.description.ping),
async execute(interaction) {
const quotes = (
Expand Down Expand Up @@ -38,4 +38,4 @@ module.exports = {
})
.then(addDeleteButton);
},
};
} as Command;
26 changes: 16 additions & 10 deletions commands/bot/status.js → commands/bot/status.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const strings = require("@resources/strings.json");
const settings = require("@resources/settings.json");
import strings from "@resources/strings.json";
import settings from "@resources/settings.json";

const warnUser = require("@helpers/warnUser");
const { ActivityType, SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const addDeleteButton = require("@helpers/addDeleteButton");
import warnUser from "@helpers/warnUser";
import {
ActivityType,
SlashCommandBuilder,
PermissionFlagsBits,
PresenceStatusData,
} from "discord.js";
import { EmbedBuilder } from "discord.js";
import addDeleteButton from "@helpers/addDeleteButton";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";

export default {
data: new SlashCommandBuilder()
.setName("status")
.setDescription(strings.command.description.status)
Expand Down Expand Up @@ -46,7 +52,7 @@ module.exports = {
return warnUser(interaction, strings.command.no_permission);

const activity = interaction.options.getString("activity", true);
const presence = interaction.options.getString("presence", true);
const presence = interaction.options.getString("presence", true) as PresenceStatusData;
const message = interaction.options.getString("message", true);

interaction.client.user.setPresence({
Expand All @@ -70,4 +76,4 @@ module.exports = {
})
.then(addDeleteButton);
},
};
} as Command;
18 changes: 9 additions & 9 deletions commands/developer/backup.js → commands/developer/backup.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const saveDB = require("@functions/saveDB");
import saveDB from "@functions/saveDB";

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js");
const warnUser = require("@helpers/warnUser");
const addDeleteButton = require("@helpers/addDeleteButton");
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js";
import warnUser from "@helpers/warnUser";
import addDeleteButton from "@helpers/addDeleteButton";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder()
.setName("backup")
.setDescription(strings.command.description.backup)
Expand Down Expand Up @@ -55,4 +55,4 @@ module.exports = {
})
.then(addDeleteButton);
},
};
} as Command;
10 changes: 5 additions & 5 deletions commands/developer/behave.js → commands/developer/behave.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const strings = require("@resources/strings.json");
import strings from "@resources/strings.json";

const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder()
.setName("behave")
.setDescription(strings.command.description.behave)
Expand All @@ -30,4 +30,4 @@ module.exports = {
return interaction.reply({ content: strings.command.behave });
}
},
};
} as Command;
14 changes: 7 additions & 7 deletions commands/developer/eval.js → commands/developer/eval.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const warnUser = require("@helpers/warnUser");
import warnUser from "@helpers/warnUser";

const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require("discord.js");
import { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } from "discord.js";
import type { Command } from "@interfaces/discord";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
export default {
data: new SlashCommandBuilder()
.setName("eval")
.setDescription("Evaluates a string of code.")
Expand Down Expand Up @@ -59,4 +59,4 @@ module.exports = {
],
});
},
};
} as Command;
14 changes: 7 additions & 7 deletions commands/developer/restart.js → commands/developer/restart.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const warnUser = require("@helpers/warnUser");
const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
import warnUser from "@helpers/warnUser";
import { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder()
.setName("restart")
.setDescription(strings.command.description.restart)
Expand All @@ -26,4 +26,4 @@ module.exports = {
// restart bot by launching index file
require("@index");
},
};
} as Command;
12 changes: 6 additions & 6 deletions commands/developer/say.js → commands/developer/say.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const strings = require("@resources/strings.json");
import strings from "@resources/strings.json";

const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const warnUser = require("@helpers/warnUser");
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import warnUser from "@helpers/warnUser";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder()
.setName("say")
.setDescription(strings.command.description.say)
Expand All @@ -24,4 +24,4 @@ module.exports = {
if (msg.deletable) await msg.delete();
await interaction.channel.send({ content });
},
};
} as Command;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const addDeleteButton = require("@helpers/addDeleteButton");
import addDeleteButton from "@helpers/addDeleteButton";

const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
import { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
import type { Command } from "@interfaces/discord";
export default {
data: new SlashCommandBuilder()
.setName("shutdown")
.setDescription(strings.command.description.shutdown)
Expand Down Expand Up @@ -37,4 +37,4 @@ module.exports = {
});
return process.exit();
},
};
} as Command;
26 changes: 13 additions & 13 deletions commands/submission/autopush.js → commands/submission/autopush.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const settings = require("@resources/settings.json");
const strings = require("@resources/strings.json");
import settings from "@resources/settings.json";
import strings from "@resources/strings.json";

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js");
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js";

const formattedDate = require("@helpers/formattedDate");
const pushTextures = require("@submission/pushTextures");
const { downloadResults } = require("@submission/handleResults");
const warnUser = require("@helpers/warnUser");
import formattedDate from "@helpers/formattedDate";
import pushTextures from "@submission/pushTextures";
import { downloadResults } from "@submission/handleResults";
import warnUser from "@helpers/warnUser";
import type { Command } from "@interfaces/discord";
import type { Pack, PackFile } from "@interfaces/database";

/** @type {import("@helpers/jsdoc").Command} */
module.exports = {
export default {
data: new SlashCommandBuilder()
.setName("autopush")
.setDescription(strings.command.description.autopush)
Expand All @@ -19,7 +20,7 @@ module.exports = {
.setDescription("Which pack to push.")
.addChoices(
{ name: "All", value: "all" },
...Object.values(require("@resources/packs.json")).map((pack) => ({
...Object.values(require("@resources/packs.json")).map((pack: Pack) => ({
name: pack.name,
value: pack.id,
})),
Expand All @@ -29,12 +30,11 @@ module.exports = {
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setDMPermission(false),
async execute(interaction) {
const submissions = require("@resources/packs.json");
const submissions: PackFile = require("@resources/packs.json");
const choice = interaction.options.getString("pack", true);
if (choice == "all" && !process.env.DEVELOPERS.includes(interaction.user.id))
return warnUser(interaction, strings.command.no_permission);

/** @type {string[]} */
const packs = choice == "all" ? Object.values(submissions) : [submissions[choice]];

const infoEmbed = new EmbedBuilder()
Expand Down Expand Up @@ -72,4 +72,4 @@ module.exports = {
],
});
},
};
} as Command;
Loading

0 comments on commit 1a7292b

Please sign in to comment.