feat: allow conditionally enabling commands
willow hai@wlo.moe
Thu, 05 Jun 2025 18:17:56 +0100
5 files changed,
21 insertions(+),
7 deletions(-)
M
src/config.ts
→
src/config.ts
@@ -31,8 +31,8 @@ const schema = z.object({
discord: discordSchema, mongodb: mongodbSchema, projects: projectSchema, - bloxlink: bloxlinkSchema, - roblox: robloxSchema, + bloxlink: bloxlinkSchema.optional(), + roblox: robloxSchema.optional(), trelloBoardId: z.string().optional(), });
M
src/handlers/interactions.ts
→
src/handlers/interactions.ts
@@ -18,6 +18,12 @@ if (!interaction.data) {
logger.info(`${fileUrl} does not have a data property, skipping`); return; } + + if (interaction.enabled === false) { + logger.info(`${interaction.data.name} was disabled, skipping`); + return; + } + commands.set(interaction.data.name, interaction); return interaction; };
M
src/types.ts
→
src/types.ts
@@ -17,6 +17,7 @@
export interface ICommand { data: ApplicationCommandData; execute: (client: Client, interaction: BaseInteraction) => Promise<void>; + enabled?: boolean; autocomplete?: (interaction: AutocompleteInteraction) => Promise<void>; buttonExecute?: ( client: Client,
M
src/utils/roblox.ts
→
src/utils/roblox.ts
@@ -9,6 +9,8 @@ export async function getRobloxUser(userId: string): Promise<{
user: GetUserResponse; thumbnail: ThumbnailResponse; }> { + if (!config.data.roblox) throw new Error("roblox API key is not configured"); + const getUserUrl = `https://apis.roblox.com/cloud/v2/users/${userId}`; const getThumbnailUrl = `https://apis.roblox.com/cloud/v2/users/${userId}:generateThumbnail`; const [userRes, thumbnailRes] = await Promise.all([@@ -37,13 +39,17 @@
export async function getConnectedRobloxUser( discordId: string, ): Promise<BLApiResponse> { - const getUserUrl = `https://api.blox.link/v4/public/discord-to-roblox/${discordId}`; + if (!config.data.bloxlink) + throw new Error("bloxlink token is not configured"); - const response = await fetch(getUserUrl, { - headers: { - Authorization: config.data.bloxlink.token, + const response = await fetch( + `https://api.blox.link/v4/public/discord-to-roblox/${discordId}`, + { + headers: { + Authorization: config.data.bloxlink.token, + }, }, - }); + ); return await response.json(); }