diff --git a/app_schema.ts b/app_schema.ts index 62a7e76..e69de29 100644 --- a/app_schema.ts +++ b/app_schema.ts @@ -1,44 +0,0 @@ -import * as discord from "discord-api-types"; -import type { AppSchema } from "discord-app"; - -export const appSchema = { - chatInput: { - name: "shorter", - description: "Manage shortlinks.", - subcommands: { - add: { - description: "Add a shortlink.", - options: { - alias: { - type: discord.ApplicationCommandOptionType.String, - description: "The alias of the shortlink", - required: true, - }, - destination: { - type: discord.ApplicationCommandOptionType.String, - description: "The destination of the shortlink", - required: true, - }, - force: { - type: discord.ApplicationCommandOptionType.Boolean, - description: "Whether to overwrite an existing shortlink", - }, - ttl: { - type: discord.ApplicationCommandOptionType.String, - description: "The time-to-live of the shortlink", - }, - }, - }, - remove: { - description: "Remove a shortlink.", - options: { - alias: { - type: discord.ApplicationCommandOptionType.String, - description: "The alias of the shortlink", - required: true, - }, - }, - }, - }, - }, -} as const satisfies AppSchema; diff --git a/deno.jsonc b/deno.jsonc index 3ad488c..425c39e 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,15 +1,13 @@ { "tasks": { - "start": "deno run -A --unstable-kv main.ts", + "start": "deno run -A --unstable-kv --env main.ts", "ngrok": "ngrok http 8080" }, "imports": { - "discord-api-types": "https://deno.land/x/discord_api_types@0.37.79/v10.ts", + "@discord-applications/app": "jsr:@discord-applications/app@^0.0.4", "codemod": "https://deno.land/x/codemod@0.0.5/github/mod.ts", "durationjs": "https://deno.land/x/durationjs@v4.1.1/mod.ts", - "discord-app": "https://deno.land/x/discord_app@0.0.4/mod.ts", - "tweetnacl": "npm:tweetnacl@1.0.3", - "@std/dotenv": "jsr:@std/dotenv@^0.222.1", - "shorter/": "./" + "shorter/": "./", + "tweetnacl": "npm:tweetnacl@1.0.3" } } diff --git a/deno.lock b/deno.lock index 354c5b3..6d34059 100644 --- a/deno.lock +++ b/deno.lock @@ -2,11 +2,27 @@ "version": "3", "packages": { "specifiers": { - "jsr:@std/dotenv@^0.222.1": "jsr:@std/dotenv@0.222.1" + "jsr:@discord-applications/app@^0.0.4": "jsr:@discord-applications/app@0.0.4", + "npm:discord-api-types@0.37.79": "npm:discord-api-types@0.37.79", + "npm:tweetnacl@^1.0.3": "npm:tweetnacl@1.0.3" }, "jsr": { - "@std/dotenv@0.222.1": { - "integrity": "61c75269cfd569033d580d9341597eb1cd4b2796323c5823033bb6d60c66d619" + "@discord-applications/app@0.0.4": { + "integrity": "fa95279d13d2ad07636799d12dd637d930a6443a0d4223e9f65493a58cb47dd5", + "dependencies": [ + "npm:discord-api-types@0.37.79", + "npm:tweetnacl@^1.0.3" + ] + } + }, + "npm": { + "discord-api-types@0.37.79": { + "integrity": "sha512-jblKMZL5f9t/pfUyhHNey8Lb9yVCcBVIPxz/JTY0raAmfj7CuFXdl9m5o/+iiB7E0vv1Kz9V7Ao5HtLRc2gH1Q==", + "dependencies": {} + }, + "tweetnacl@1.0.3": { + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dependencies": {} } } }, @@ -44,172 +60,16 @@ "https://deno.land/x/codemod@0.0.5/github/tree/base64.ts": "4854bba36ec3fc501693d27cece4f5725797b522cd7dfe0c721befedefd956f3", "https://deno.land/x/codemod@0.0.5/github/tree/github_create_tree_builder.ts": "cc3d4efa23ecce94eb1b3dbaf8cdd16dff3a14065335302365009df5a20a7c17", "https://deno.land/x/codemod@0.0.5/github/tree/github_create_tree_builder_interface.ts": "0623f3c8a5285b58898555c2718cd2f7ec6e1d5619ee30405ef3297d5ea8802b", - "https://deno.land/x/discord_api_types@0.37.65/gateway/common.ts": "fb67003adda424df76c2726e0624d709c5a16e3694d6b75facd587d121fe121f", - "https://deno.land/x/discord_api_types@0.37.65/gateway/v10.ts": "249f6de453d606b291fc548a27204b4a71bc462d3204c7a71622e016773ea9ab", - "https://deno.land/x/discord_api_types@0.37.65/globals.ts": "7d8879654c4741ac071668ad52f2659bcdb66694cfe7da306c8437ec752807a7", - "https://deno.land/x/discord_api_types@0.37.65/payloads/common.ts": "4449a87e8c1cf6d091f667370be3a42609c1a4f44cbe5f9881f7fc0e6f6920cc", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/attachment.ts": "c66dccd54c1b84d073f2e1caa466e551b8045a84a2e8a88a1bfbc7e2c64a703d", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/base.ts": "f6a2556e14d489e1f0e5ddeb3a0303e2603e25330530dd9263e176013c5f51eb", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/boolean.ts": "65e29561b61785ca4ede4b1b4a88c5fc0696cfdf1fa74d5197588c196ee7ae98", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/channel.ts": "73c7fc49de242e1ce3be958375fd810750aed83553ef3860e3cddf858f9eb464", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/integer.ts": "a25d24a3e54d647c7039b99e3208fc0fc2228d174f6dcc421e93919b8154a011", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/mentionable.ts": "742e42857465866e0c08b587d7fb5ccd81d4705c61ce4cd6b97ad5692e88e969", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/number.ts": "be974ea68f5fdf55d7a7f5d3faf48a3193777d432b1aa9087afc204bcb916284", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/role.ts": "a57114d0f7eeee4ab7cf217a865dd9dbd9096d007c556aec6185d64257100f41", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/shared.ts": "9e2d3b3530280f6de5f9b6de1bb81e8a905998e058f784a9b041e48a96cd93d2", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/string.ts": "33ab12dab64544a70729b9b66b5a9790964ea779f05d4ab1a1e190e7c1b59e98", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommand.ts": "0013737da6d2b54e2f413fbf31cf9c84ea51bd9204b615cb4fd19b420f856cb2", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommandGroup.ts": "db5cc701bcb3d68c094de409da39c9a2b8834dc0d5038e5f963c96e5eaf412ac", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/user.ts": "ed2871693744298225ba53ddfb18d3e7afff20a34f413822d5b1193918aea27f", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/chatInput.ts": "46362da4e56c99cc69331481330d6e95c31d5e46f4cc36ec23f03cafbb687d52", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/contextMenu.ts": "89aed5f05f75d482e40259f55d0172143a90c1980d060d16545bdc14b68b29c4", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/internals.ts": "5eb5ea13a1247c73c0611886dea09ab8d632a9c5555ff0f33d44cd379fd75a08", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/permissions.ts": "ddca14b62e6afd418c1417117ffcc7cfb2ea5e5cc5353b4a0598435bdea45fb5", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/applicationCommands.ts": "b0646f2930d38113389bd1ecf8c605ac5af8fc40f93fafd17f968150419fac14", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/autocomplete.ts": "821ae50ff9845cac4b03169dbd4c4b187d8399765eb1f0d658d477c68e4c6136", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/base.ts": "ca2df849ee55f2fbd5fa9626c48811de7cc9b69979838c6c54982a5e3a44219a", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/messageComponents.ts": "08faa77d1c1d9a33359a962b78b695304e27cb6435af319b41e9a9d3b395adb2", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/modalSubmit.ts": "3a02d2d7df5bcdb1ffcd089f15e0d82ab65dcc0cefa904c6e0621f46edac041e", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/ping.ts": "096ce582e9af373649fd5355cccd7424adceaffb73367b5301f1594ef5a3c264", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/responses.ts": "c1b0fc1ecca7858de08720e0222660e23935ebdd563e1964878a525eb29f062b", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/application.ts": "7ec267bf4b809534c8c5e919a7b1da7b33190f9d545445146e007ddb9d0554f5", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/auditLog.ts": "ced9d28a20b2bb201761c37ef266ace325a808a405b7472d70ad6df3b56c4d87", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/autoModeration.ts": "9ccb4408f1c6392d9619fac159997e08e660080b3f9567a1619163a40329e3a2", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/channel.ts": "47af2e40deb2ce6dd00438cd41d67d00f311ac330db6c27aed74da104776baf8", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/emoji.ts": "b9a30b16e1ec4dc15d6149e59aa48b02ad57a51335b7be5a7f5368db0491b3dd", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/gateway.ts": "4ce715fa94eadf5e2ba6adfc4a3bf99bac5d19c4787794ee1774b645a324db72", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/guild.ts": "4c03e054fc07d8db0ee7fa2b6f645f57f7642de0d28a704aa15047a51544f710", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/guildScheduledEvent.ts": "bf506b7807501b71077751ec793e719c5515e1bb405dec5cc4371a61b03cf8b9", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/interactions.ts": "17dabe94016dad3d0d7fdc0aa812bf5b0b366465dd72cd0b01168880778cc60d", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/invite.ts": "92c09f549482a4e2ad5a3c1062debfb262c6fe4b6740581175a0b8108873ab01", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/mod.ts": "83d68247652307f1587d71ac6983fd795ad7b9d5c92540a65207ea9293b09812", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/monetization.ts": "9a91c8dbb4f4c505e561630f0205f821e6877a5ea74faf4eaad9c154f5cc0d02", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/oauth2.ts": "dfb9f09fb44bf5faaa73ad4488ebe408905907d5fd46404895317f4e7c378489", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/permissions.ts": "5e7990e6dad3e35f8c130dc52de4bbf63afe5d6ad98e1c56b09da3ead94ad5a4", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/stageInstance.ts": "f0b9ee8c24c67298086fa32cb0595f6c29710d81b6fe85b958d48e6c549c4cb8", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/sticker.ts": "8511b5cdbe8289ce13fd51c2e96d24548345111b8d9f9c907dd3336f10e795bf", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/teams.ts": "101044d8c48a3cbabb60048eff9f69588bdd1ea84d1825de0372b4e23ad7ccbe", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/template.ts": "c6bee171ed0ce61fc8b59de42541a023bdcde62718deb42325397e5c82efdc27", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/user.ts": "361b93e3683fcf611c021c4f39c7501ca1482e999887d97a4b0a09398b4618c5", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/voice.ts": "62d03a540f2e78e5f3989f71a0ee1ec682ef7306a4fa096f89118cbd82351d47", - "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/webhook.ts": "7fc370f40a84f12a6e57ddda7cf2814f15039d6320b46979db0b49d5b91e303b", - "https://deno.land/x/discord_api_types@0.37.65/rest/common.ts": "36f7f83f8c1b95d68d9a55bc00b1d54eb4672186960962684826581f13ef9643", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/application.ts": "9f1c388bb5ccba192a57923c0aabe525f47de2d5ef8710a5d9a0cd0a3fa55317", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/auditLog.ts": "39a0914b6c51445023d82c3e3e66c9866cbb3cb6774d3e7eac63414ea9bcbfec", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/autoModeration.ts": "3d388fd9a91c34f04b5e3e1b6ffe12029fb48b511f37ff88042325ec6cbc6605", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/channel.ts": "421ab1178e83765fe403c75b8e481823bd10a9288c1487163c4f1b5049d2ca7c", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/emoji.ts": "9f694a1bd63886c62a87b4320f3bfa5d4f534b2d87c317d77d572d10522df3aa", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/gateway.ts": "747cb95c9a8bca4e52423c780d5fc492fb0dab2b6015cd7e51e890e8d51acf29", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/guild.ts": "6822854ad9026c2be656acc81e8161d45d650d44170e664762ec7e67b1f15e4e", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/guildScheduledEvent.ts": "29d361f395d8cd1ecb47550615d19e10793d513cc5ad8d32895da2cc9cd0fd89", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/interactions.ts": "2b6decdfff921b6aa8f0e6e5c61d38469a0178c5ecf1a18dd17ad6738143e662", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/invite.ts": "28f8e740bdaa782c9d9d504049323762b5c1180348019dc5f9e0a900ec11213e", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/mod.ts": "de48b0db06354fc8d37034a6cc5052a56fa38f4105db4df2157cfca8c164fbba", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/monetization.ts": "93f066371177fc847576df6875cd5019b116bc7ad0b2559395452d75920085a4", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/oauth2.ts": "b659a35654c17767480d142c46c36f5fe2544346875745e3f654c5e7c3d9f3f9", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/stageInstance.ts": "a090ff8b54f77188323af5d06cdef9c42738edf9a9b0eba8aad3c89d5ac5569f", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/sticker.ts": "1f7f2729308a0ec1fe373b5df7ac71bafc200132f1a06df7e75bf5ce1d1069c1", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/template.ts": "0ad41c3c85571d3c5b0bec3914c678a21f376ec162ef0d3f1f7731a8d1d1009c", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/user.ts": "60cfa227426c791021e9e8f769287e997477e722db5a3c577a9ec54078aaffca", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/voice.ts": "cdbe9d6c39c8f44635d8632bf62a95b8c15877b92c56ddf69df2072bb1a74edc", - "https://deno.land/x/discord_api_types@0.37.65/rest/v10/webhook.ts": "f4d47265bc69f9fa32efd0fd620db8b1d1996d2184cf5ac624abd104862d6ae0", - "https://deno.land/x/discord_api_types@0.37.65/rpc/common.ts": "a693352ffd86ae9e995fb3fbfbfd2be30896257ecb83c5611050f060b08de4ef", - "https://deno.land/x/discord_api_types@0.37.65/rpc/v10.ts": "fbaad9f3d73fce88e76b0e52ad5345093f18077e4293937c9ec0ee24415b9a93", - "https://deno.land/x/discord_api_types@0.37.65/utils/internals.ts": "cb70895ba89f7947c38f7fa447b0190cb14b5585be323414cda53d2ccb19b16c", - "https://deno.land/x/discord_api_types@0.37.65/utils/v10.ts": "056bd036f8c65365ff28eb63ec6897811d51921cca6d068392dd1ca5b397ae62", - "https://deno.land/x/discord_api_types@0.37.65/v10.ts": "f3f23492c59e77859aba5b34431edf3668c37f722d7f70c2e1ef7ba4bcda3010", - "https://deno.land/x/discord_api_types@0.37.79/gateway/common.ts": "c568382f2e1a8bdf5c5d37b622c32ad5428b70ea9eb6abef40914ce4e4de56a0", - "https://deno.land/x/discord_api_types@0.37.79/gateway/v10.ts": "572a1c3bfc7f564cffcd0312d282c6e0b494cd14fef7106edd77f96c7fc97fa2", - "https://deno.land/x/discord_api_types@0.37.79/globals.ts": "7d8879654c4741ac071668ad52f2659bcdb66694cfe7da306c8437ec752807a7", - "https://deno.land/x/discord_api_types@0.37.79/payloads/common.ts": "f4e3a52801ec5e93c55177531a0a09b6ee9d0b5d7172e1e51c042bd58cce8c2e", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/attachment.ts": "c66dccd54c1b84d073f2e1caa466e551b8045a84a2e8a88a1bfbc7e2c64a703d", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/base.ts": "f6a2556e14d489e1f0e5ddeb3a0303e2603e25330530dd9263e176013c5f51eb", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/boolean.ts": "65e29561b61785ca4ede4b1b4a88c5fc0696cfdf1fa74d5197588c196ee7ae98", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/channel.ts": "73c7fc49de242e1ce3be958375fd810750aed83553ef3860e3cddf858f9eb464", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/integer.ts": "a25d24a3e54d647c7039b99e3208fc0fc2228d174f6dcc421e93919b8154a011", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/mentionable.ts": "742e42857465866e0c08b587d7fb5ccd81d4705c61ce4cd6b97ad5692e88e969", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/number.ts": "be974ea68f5fdf55d7a7f5d3faf48a3193777d432b1aa9087afc204bcb916284", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/role.ts": "a57114d0f7eeee4ab7cf217a865dd9dbd9096d007c556aec6185d64257100f41", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/shared.ts": "de4aee14f9cd21e8dbff6c523cb90be9f4273893347fef00930919a976f598b6", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/string.ts": "33ab12dab64544a70729b9b66b5a9790964ea779f05d4ab1a1e190e7c1b59e98", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommand.ts": "0013737da6d2b54e2f413fbf31cf9c84ea51bd9204b615cb4fd19b420f856cb2", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommandGroup.ts": "db5cc701bcb3d68c094de409da39c9a2b8834dc0d5038e5f963c96e5eaf412ac", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/_chatInput/user.ts": "ed2871693744298225ba53ddfb18d3e7afff20a34f413822d5b1193918aea27f", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/chatInput.ts": "1f88245356202857d7a38d21af8ea1c96a65d7da5563734e5ea4af67ba51d1ae", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/contextMenu.ts": "e40500fa8c61f624575a789516e12d6219ce5299fa88da657963c97772ac00df", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/internals.ts": "5eb5ea13a1247c73c0611886dea09ab8d632a9c5555ff0f33d44cd379fd75a08", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/_applicationCommands/permissions.ts": "5af8dd6bac57e87d1339ab5e1c7465aab5c4e4f4aeac7a4808ff2cc3d1a315fc", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/applicationCommands.ts": "8c42e0a2416819a17b028878780f90f926f889b649f7195a8b95816a1ba9085f", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/autocomplete.ts": "821ae50ff9845cac4b03169dbd4c4b187d8399765eb1f0d658d477c68e4c6136", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/base.ts": "ae318712d1befd8ef225916ef83c236b821f59555f988c158e5399e98289eff6", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/messageComponents.ts": "9248c572492a5ea11a05c4f8f58c99f94b41425794b1133d5dd389127197eabf", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/modalSubmit.ts": "3a02d2d7df5bcdb1ffcd089f15e0d82ab65dcc0cefa904c6e0621f46edac041e", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/ping.ts": "096ce582e9af373649fd5355cccd7424adceaffb73367b5301f1594ef5a3c264", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/_interactions/responses.ts": "ae34794d507b38c2feb7e653fe1f436df194fcef6f945a25deb1ab0842db5b66", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/application.ts": "7ec267bf4b809534c8c5e919a7b1da7b33190f9d545445146e007ddb9d0554f5", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/auditLog.ts": "5a4f411a807665442dfdcc41a3e7d2ce23be902a2e57c365e8f3785d104e3db2", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/autoModeration.ts": "9ccb4408f1c6392d9619fac159997e08e660080b3f9567a1619163a40329e3a2", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/channel.ts": "469d3fe37ae22e6b39c0243dbb38a4927cc419cd346054f39aba681ae95539e2", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/emoji.ts": "b9a30b16e1ec4dc15d6149e59aa48b02ad57a51335b7be5a7f5368db0491b3dd", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/gateway.ts": "a00dd57a6756a98a024502d76381b57a66321b4d91d663de14e325e5ff21ae48", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/guild.ts": "99a524ceebdeec5721262dd436e02051848f154b2830ea94ba7efd4f2b0e2b23", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/guildScheduledEvent.ts": "16073e6dc7193eac59d6de79c1ab1070daf02b9466dccc866100cb7a3780be59", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/interactions.ts": "d2c31c147ec49663dc26c314eb2e764537dbf7f2f82eb1e659ae4dea9609ba41", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/invite.ts": "9785b4467016f73f8d2633cf31f7fd3470e94bfa4ce7ad22fe9ff2dcf1e67ad8", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/mod.ts": "83d68247652307f1587d71ac6983fd795ad7b9d5c92540a65207ea9293b09812", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/monetization.ts": "9a91c8dbb4f4c505e561630f0205f821e6877a5ea74faf4eaad9c154f5cc0d02", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/oauth2.ts": "dfb9f09fb44bf5faaa73ad4488ebe408905907d5fd46404895317f4e7c378489", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/permissions.ts": "5e7990e6dad3e35f8c130dc52de4bbf63afe5d6ad98e1c56b09da3ead94ad5a4", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/stageInstance.ts": "0f7ebce1aba67578f178a7c2aba783b4ec0e639c99d0a353888d678a92685c5c", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/sticker.ts": "6afaf40e19632cad9e3935477ab7d77a163a5d7419f6fdcc122d4762982513ec", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/teams.ts": "101044d8c48a3cbabb60048eff9f69588bdd1ea84d1825de0372b4e23ad7ccbe", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/template.ts": "c6bee171ed0ce61fc8b59de42541a023bdcde62718deb42325397e5c82efdc27", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/user.ts": "27284259de8fc67091cc652c7a6dd91c9e0286c2a6caf329eb17038762a02cc9", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/voice.ts": "62d03a540f2e78e5f3989f71a0ee1ec682ef7306a4fa096f89118cbd82351d47", - "https://deno.land/x/discord_api_types@0.37.79/payloads/v10/webhook.ts": "7fc370f40a84f12a6e57ddda7cf2814f15039d6320b46979db0b49d5b91e303b", - "https://deno.land/x/discord_api_types@0.37.79/rest/common.ts": "a9a9021e7dda3413dbeffd7584304fb467173f1a44f71d53ca1bb204f57afe2d", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/application.ts": "2a1cbde372ed9a4c9c6486bb5a59448f15565374ed055f93bb44401e028b87ca", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/auditLog.ts": "39a0914b6c51445023d82c3e3e66c9866cbb3cb6774d3e7eac63414ea9bcbfec", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/autoModeration.ts": "3d388fd9a91c34f04b5e3e1b6ffe12029fb48b511f37ff88042325ec6cbc6605", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/channel.ts": "a3dc29bfbe589eb0fdf461bfe32d3efb2cfd16685f88787130438d51b097fcb8", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/emoji.ts": "9f694a1bd63886c62a87b4320f3bfa5d4f534b2d87c317d77d572d10522df3aa", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/gateway.ts": "747cb95c9a8bca4e52423c780d5fc492fb0dab2b6015cd7e51e890e8d51acf29", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/guild.ts": "e6e28477a878897454b02dfa40ba86f30647c54e2a07fa6ddea093f55d438769", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/guildScheduledEvent.ts": "29d361f395d8cd1ecb47550615d19e10793d513cc5ad8d32895da2cc9cd0fd89", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/interactions.ts": "5ffe19bba79304ecc0bf7caa7d8e747688b02440372be537e303750d9ade2e10", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/invite.ts": "28f8e740bdaa782c9d9d504049323762b5c1180348019dc5f9e0a900ec11213e", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/mod.ts": "d1f5103f2d5ac5fd351c824281834abb7810d5dc614d0e14e323910b46336e86", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/monetization.ts": "4ce23e105519637eb0a46aed552d7e71c33924ed927390dc9c5e4a1aa6eeb5da", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/oauth2.ts": "72c27a1d44d4e5dff8ae10619989ad8786a783b477d7f84b9bebfbdd75481006", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/stageInstance.ts": "a090ff8b54f77188323af5d06cdef9c42738edf9a9b0eba8aad3c89d5ac5569f", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/sticker.ts": "1f7f2729308a0ec1fe373b5df7ac71bafc200132f1a06df7e75bf5ce1d1069c1", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/template.ts": "0ad41c3c85571d3c5b0bec3914c678a21f376ec162ef0d3f1f7731a8d1d1009c", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/user.ts": "8ea167fc3537f4af0ec4618a3ee4f74819de9b8eeb588ec228583943844b6e0c", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/voice.ts": "cdbe9d6c39c8f44635d8632bf62a95b8c15877b92c56ddf69df2072bb1a74edc", - "https://deno.land/x/discord_api_types@0.37.79/rest/v10/webhook.ts": "7e2b75d68bc543f58c893bc41e268731a85d18b765618b6a3d477c46e76adee1", - "https://deno.land/x/discord_api_types@0.37.79/rpc/common.ts": "a693352ffd86ae9e995fb3fbfbfd2be30896257ecb83c5611050f060b08de4ef", - "https://deno.land/x/discord_api_types@0.37.79/rpc/v10.ts": "fbaad9f3d73fce88e76b0e52ad5345093f18077e4293937c9ec0ee24415b9a93", - "https://deno.land/x/discord_api_types@0.37.79/utils/internals.ts": "9a8b59a45efe216ad88d73036005babe17a475a470a80cbe5d4bba2f5bb7660e", - "https://deno.land/x/discord_api_types@0.37.79/utils/v10.ts": "2bf6a001a02e9958d1da37df412c11b04cd6ae2a6df6cfbae6c051088c37474b", - "https://deno.land/x/discord_api_types@0.37.79/v10.ts": "f3f23492c59e77859aba5b34431edf3668c37f722d7f70c2e1ef7ba4bcda3010", - "https://deno.land/x/discord_app@0.0.4/app.ts": "9ae505a728d3a43d2fa42cf443605da2115e371df7b42c1d67201ca0cb904515", - "https://deno.land/x/discord_app@0.0.4/app_handler.ts": "8bd6cb6e4bd897c27322e0478c869ced87276e44c0bb7ccf5cbbabaecba9f5fa", - "https://deno.land/x/discord_app@0.0.4/deps.ts": "33b3ad17eef3ae09dd8aaf9a6201e6dcba2f5c412af60c9193f9f956d25903bb", - "https://deno.land/x/discord_app@0.0.4/discord_api.ts": "398d7fec0898fba51735b3d44bd6d012a8203fc0893fa826f7101fbf914bce57", - "https://deno.land/x/discord_app@0.0.4/discord_api_types.ts": "7231c7ecff41407628097a4fe2d08e4afd74f189d2d4346c56c3224b01dd4ebd", - "https://deno.land/x/discord_app@0.0.4/mod.ts": "bbad0ae8c89db1e43ed9dce108854729ddd7a962d41fc4b6035d3d3f7aa8a752", "https://deno.land/x/durationjs@v4.1.1/mod.ts": "a7f9d3f38823caa9965f3e61f74a75fb09be548cca2517bd91be7ce15e4b35f1", "https://deno.land/x/durationjs@v4.1.1/src/duration.ts": "dd82b556c311c83513b1e0e7184e27bacb7f1fa992518b56dfbdd69b7b79cb5b", "https://deno.land/x/durationjs@v4.1.1/src/in_words.ts": "1839490e2cb17fec2871bf87d6c7f7435c68416f9360d9f140777936d4680137", "https://deno.land/x/github_api_types@2023-05-17-05-41/mod.ts": "dc3a5cd3176c78085b49601e9c3fccac24809b037929230293255edabafbd0bb", - "https://esm.sh/fast-json-patch@3.1.1": "fd59bab1fabdb3e7e2ce8204aa92113dc451708797021fff6f96b8ff265faedf", - "https://esm.sh/tweetnacl@1.0.3": "fe5086fc2857018dc6118351ec0790016454d787af13301d65331c9a08eabb6a", - "https://esm.sh/v124/fast-json-patch@3.1.1/deno/fast-json-patch.mjs": "19183b256388e7af3ffb65022a634e00109c308fe79071cd550dd5ab1f0a571b", - "https://esm.sh/v125/tweetnacl@1.0.3/denonext/tweetnacl.mjs": "e3f326d197a7d2dc580dc57db86b5adb6374d9a64de2d5b6a1711612c930c1c7" + "https://esm.sh/fast-json-patch@3.1.1": "af46ff8943971c21b2722f5d715096f5b8eacea5174c463c2635d6d4e40351db", + "https://esm.sh/v135/fast-json-patch@3.1.1/denonext/fast-json-patch.mjs": "9007860190336aa381bde2411eb991d3d70fe378c0cc204f099d4fc9bd6b7619" }, "workspace": { "dependencies": [ - "jsr:@std/dotenv@^0.222.1", + "jsr:@discord-applications/app@^0.0.4", "npm:tweetnacl@1.0.3" ] } diff --git a/env.ts b/env.ts index af04776..564f410 100644 --- a/env.ts +++ b/env.ts @@ -1,7 +1,3 @@ -import { load } from "@std/dotenv"; - -await load({ export: true }); - /** * PORT is the port to listen on. */ diff --git a/lib/discord/discord_api_client.ts b/lib/discord/discord_api_client.ts deleted file mode 100644 index 61584aa..0000000 --- a/lib/discord/discord_api_client.ts +++ /dev/null @@ -1,81 +0,0 @@ -import type { - DiscordAPIClientInterface, - EditOriginalInteractionResponseOptions, - RegisterCommandOptions, -} from "./discord_api_client_interface.ts"; - -/** - * DISCORD_API_URL is the base URL for the Discord API. - */ -export const DISCORD_API_URL = "https://discord.com/api/v10"; - -/** - * DiscordAPIClient is a client for the Discord API. - */ -export class DiscordAPIClient implements DiscordAPIClientInterface { - async registerCommand(options: RegisterCommandOptions): Promise { - const url = makeRegisterCommandsURL(options.botID); - const response = await fetch(url, { - method: "POST", - headers: new Headers([ - ["Content-Type", "application/json"], - ["Authorization", makeBotAuthorization(options.botToken)], - ]), - body: JSON.stringify(options.app), - }); - if (!response.ok) { - console.error("text:", await response.text()); - throw new Error( - `Failed to register command: ${response.status} ${response.statusText}`, - ); - } - } - - async editOriginalInteractionResponse( - options: EditOriginalInteractionResponseOptions, - ): Promise { - const url = makeEditOriginalInteractionResponseURL( - options.botID, - options.interactionToken, - ); - const response = await fetch(url, { - method: "PATCH", - headers: new Headers([["Content-Type", "application/json"]]), - body: JSON.stringify({ content: options.content }), - }); - if (!response.ok) { - console.error("text:", await response.text()); - throw new Error( - `Failed to edit original interaction response: ${response.status} ${response.statusText}`, - ); - } - } -} - -/** - * makeBotAuthorization makes the Authorization header for a bot. - */ -export function makeBotAuthorization(botToken: string) { - return botToken.startsWith("Bot ") ? botToken : `Bot ${botToken}`; -} - -/** - * makeRegisterCommandsURL makes the URL to register a Discord application command. - */ -export function makeRegisterCommandsURL( - clientID: string, - base = DISCORD_API_URL, -) { - return new URL(`${base}/applications/${clientID}/commands`); -} - -/** - * makeEditOriginalInteractionResponseURL makes the URL to edit the original interaction response. - */ -export function makeEditOriginalInteractionResponseURL( - clientID: string, - interactionToken: string, - base = DISCORD_API_URL, -) { - return `${base}/webhooks/${clientID}/${interactionToken}/messages/@original`; -} diff --git a/lib/discord/discord_api_client_interface.ts b/lib/discord/discord_api_client_interface.ts deleted file mode 100644 index 4232537..0000000 --- a/lib/discord/discord_api_client_interface.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type * as discord from "discord-api-types"; - -/** - * DiscordAPIClientInterface is the interface for the Discord API Client. - */ -export interface DiscordAPIClientInterface { - /** - * registerCommand overwrites the Discord Slash Commands associated with the server. - * - * Based on this cURL command: - * ```bash - * BOT_TOKEN='replace_me_with_bot_token' - * CLIENT_ID='replace_me_with_client_id' - * curl -X POST \ - * -H 'Content-Type: application/json' \ - * -H "Authorization: Bot $BOT_TOKEN" \ - * -d '{"name":"hello","description":"Greet a person","options":[{"name":"name","description":"The name of the person","type":3,"required":true}]}' \ - * "https://discord.com/api/v8/applications/$CLIENT_ID/commands" - * ``` - */ - registerCommand(o: RegisterCommandOptions): Promise; - - /** - * editOriginalInteractionResponse edits the original interaction response. - */ - editOriginalInteractionResponse( - o: EditOriginalInteractionResponseOptions, - ): Promise; -} - -/** - * RegisterCommandOptions is the initialization to register a Discord application command. - */ -export interface RegisterCommandOptions { - botID: string; - botToken: string; - app: discord.RESTPostAPIApplicationCommandsJSONBody; -} - -/** - * EditOriginalInteractionResponseOptions is the initialization to edit the original interaction response. - */ -export interface EditOriginalInteractionResponseOptions { - botID: string; - botToken: string; - interactionToken: string; - content: string; -} diff --git a/lib/discord/mod.ts b/lib/discord/mod.ts deleted file mode 100644 index dfd7697..0000000 --- a/lib/discord/mod.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./discord_api_client_interface.ts"; -export * from "./discord_api_client.ts"; diff --git a/main.ts b/main.ts index 51f1226..b6b01ea 100644 --- a/main.ts +++ b/main.ts @@ -1,9 +1,17 @@ -import * as discord from "discord-api-types"; import { Duration } from "durationjs"; -import { createApp } from "discord-app"; +import type { + APIInteractionResponseDeferredChannelMessageWithSource, + AppSchema, +} from "@discord-applications/app"; +import { + ApplicationCommandOptionType, + createApp, + DiscordAPI, + InteractionResponseType, + MessageFlags, +} from "@discord-applications/app"; import type { ShorterOptions } from "shorter/lib/shorter/mod.ts"; import { shorter } from "shorter/lib/shorter/mod.ts"; -import { DiscordAPIClient } from "shorter/lib/discord/mod.ts"; import { addTTLMessage, makeTTLMessageListener, @@ -16,14 +24,59 @@ import { GITHUB_TOKEN, PORT, } from "shorter/env.ts"; -import { appSchema } from "./app_schema.ts"; const INVITE_URL = `https://discord.com/api/oauth2/authorize?client_id=${DISCORD_CLIENT_ID}&scope=applications.commands`; const APPLICATION_URL = `https://discord.com/developers/applications/${DISCORD_CLIENT_ID}/bot`; -const discordAPI = new DiscordAPIClient(); +const discordAPI = new DiscordAPI({ + applicationID: DISCORD_CLIENT_ID, + token: DISCORD_TOKEN, + publicKey: DISCORD_PUBLIC_KEY, +}); + +export const shorterSchema = { + chatInput: { + name: "Shorter", + description: "Manage shortlinks.", + subcommands: { + add: { + description: "Add a shortlink.", + options: { + alias: { + type: ApplicationCommandOptionType.String, + description: "The alias of the shortlink", + required: true, + }, + destination: { + type: ApplicationCommandOptionType.String, + description: "The destination of the shortlink", + required: true, + }, + force: { + type: ApplicationCommandOptionType.Boolean, + description: "Whether to overwrite an existing shortlink", + }, + ttl: { + type: ApplicationCommandOptionType.String, + description: "The time-to-live of the shortlink", + }, + }, + }, + remove: { + description: "Remove a shortlink.", + options: { + alias: { + type: ApplicationCommandOptionType.String, + description: "The alias of the shortlink", + required: true, + }, + }, + }, + }, + }, +} as const satisfies AppSchema; if (import.meta.main) { await main(); @@ -41,12 +94,13 @@ export async function main() { }); // Create the Discord application. - const handleInteraction = await createApp( + const shorterApp = await createApp( { + schema: shorterSchema, applicationID: DISCORD_CLIENT_ID, publicKey: DISCORD_PUBLIC_KEY, - register: { token: DISCORD_TOKEN }, - schema: appSchema, + token: DISCORD_TOKEN, + register: true, }, { add(interaction) { @@ -58,9 +112,9 @@ export async function main() { !interaction.member.roles.some((role) => DISCORD_ROLE_ID === role) ) { return { - type: discord.InteractionResponseType.ChannelMessageWithSource, + type: InteractionResponseType.ChannelMessageWithSource, data: { - flags: discord.MessageFlags.Ephemeral, + flags: MessageFlags.Ephemeral, content: "You do not have permission to use this command.", }, }; @@ -101,8 +155,6 @@ export async function main() { // Send the success message. await discordAPI.editOriginalInteractionResponse({ - botID: DISCORD_CLIENT_ID, - botToken: DISCORD_TOKEN, interactionToken: interaction.token, content, }); @@ -124,8 +176,6 @@ export async function main() { .catch((error) => { if (error instanceof Error) { discordAPI.editOriginalInteractionResponse({ - botID: DISCORD_CLIENT_ID, - botToken: DISCORD_TOKEN, interactionToken: interaction.token, content: `Error: ${error.message}`, }); @@ -136,9 +186,8 @@ export async function main() { // Acknowledge the interaction. return { - type: - discord.InteractionResponseType.DeferredChannelMessageWithSource, - } satisfies discord.APIInteractionResponseDeferredChannelMessageWithSource; + type: InteractionResponseType.DeferredChannelMessageWithSource, + } satisfies APIInteractionResponseDeferredChannelMessageWithSource; }, remove(interaction) { if (!interaction.member?.user) { @@ -149,9 +198,9 @@ export async function main() { !interaction.member.roles.some((role) => DISCORD_ROLE_ID === role) ) { return { - type: discord.InteractionResponseType.ChannelMessageWithSource, + type: InteractionResponseType.ChannelMessageWithSource, data: { - flags: discord.MessageFlags.Ephemeral, + flags: MessageFlags.Ephemeral, content: "You do not have permission to use this command.", }, }; @@ -172,8 +221,6 @@ export async function main() { .then(async (result) => { // Send the success message. await discordAPI.editOriginalInteractionResponse({ - botID: DISCORD_CLIENT_ID, - botToken: DISCORD_TOKEN, interactionToken: interaction.token, content: `Removed \`${interaction.data.parsedOptions.alias}\` in commit [${result.message}](https://acmcsuf.com/code/commit/${result.sha}).`, @@ -182,8 +229,6 @@ export async function main() { .catch((error) => { if (error instanceof Error) { discordAPI.editOriginalInteractionResponse({ - botID: DISCORD_CLIENT_ID, - botToken: DISCORD_TOKEN, interactionToken: interaction.token, content: `Error: ${error.message}`, }); @@ -194,9 +239,8 @@ export async function main() { // Acknowledge the interaction. return { - type: - discord.InteractionResponseType.DeferredChannelMessageWithSource, - } satisfies discord.APIInteractionResponseDeferredChannelMessageWithSource; + type: InteractionResponseType.DeferredChannelMessageWithSource, + } satisfies APIInteractionResponseDeferredChannelMessageWithSource; }, }, ); @@ -213,7 +257,7 @@ export async function main() { console.log("Discord application information:", APPLICATION_URL); }, }, - handleInteraction, + shorterApp, ); }