From c01c40336b32777e49d8d2cf7a9d86a396409e52 Mon Sep 17 00:00:00 2001 From: artie Date: Mon, 10 Feb 2025 21:36:18 +0100 Subject: [PATCH] add httpcat --- src/commands/utility/httpcat.ts | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/commands/utility/httpcat.ts diff --git a/src/commands/utility/httpcat.ts b/src/commands/utility/httpcat.ts new file mode 100644 index 0000000..9da8321 --- /dev/null +++ b/src/commands/utility/httpcat.ts @@ -0,0 +1,35 @@ +import { SlashCommandBuilder } from "discord.js"; +import { defineCommand } from ".."; +import { STATUS_CODES } from "http"; + +export default defineCommand({ + data: new SlashCommandBuilder() + .setName("httpcat") + .setDescription("Sends a cat for the given HTTP code") + .addIntegerOption((option) => + option + .setName("code") + .setDescription("HTTP code") + .setRequired(true) + .setAutocomplete(true) + ), + + async autocomplete(interaction) { + await interaction.respond( + Object.keys(STATUS_CODES) + .filter((code) => + code.startsWith( + interaction.options.getInteger("code", true).toString() + ) + ) + .map((code) => ({ name: code, value: +code })) + .slice(0, 25) + ); + }, + + async execute(interaction) { + let code = interaction.options.getInteger("code", true); + code = typeof STATUS_CODES[code] === "string" ? code : 404; + await interaction.reply(`https://http.cat/${code}`); + }, +});