|
9 | 9 | import { readdir } from "node:fs/promises"; |
10 | 10 | import { join } from "node:path"; |
11 | 11 | import { InteractionOptionResolver } from "@sapphire/discord-utilities"; |
| 12 | +import Polka from "polka"; |
12 | 13 | import App from "./app.js"; |
13 | 14 | import { ChatInputCommand, ContextMenuCommand } from "#structures"; |
14 | 15 | import { log, parser, verifyKey } from "#util"; |
@@ -37,64 +38,63 @@ for (const folder of await readdir(new URL("commands", import.meta.url))) { |
37 | 38 | } |
38 | 39 | } |
39 | 40 |
|
40 | | -app.server.use(parser, verifyKey).post("/", async (req, res) => { |
41 | | - const interaction: APIInteraction = req.body; |
| 41 | +Polka() |
| 42 | + .use(parser, verifyKey) |
| 43 | + .post("/", async (req, res) => { |
| 44 | + const interaction: APIInteraction = req.body; |
42 | 45 |
|
43 | | - app.emit("interaction", interaction); |
| 46 | + app.emit("interaction", interaction); |
44 | 47 |
|
45 | | - switch (interaction.type) { |
46 | | - case InteractionType.Ping: |
47 | | - res |
48 | | - .setHeader("Content-Type", "application/json") |
49 | | - .writeHead(200) |
50 | | - .end(JSON.stringify({ type: InteractionResponseType.Pong })); |
51 | | - break; |
52 | | - case InteractionType.ApplicationCommand: { |
53 | | - const options = new InteractionOptionResolver(interaction); |
| 48 | + switch (interaction.type) { |
| 49 | + case InteractionType.Ping: |
| 50 | + res |
| 51 | + .setHeader("Content-Type", "application/json") |
| 52 | + .writeHead(200) |
| 53 | + .end(JSON.stringify({ type: InteractionResponseType.Pong })); |
| 54 | + break; |
| 55 | + case InteractionType.ApplicationCommand: { |
| 56 | + const options = new InteractionOptionResolver(interaction); |
54 | 57 |
|
55 | | - switch (interaction.data.type) { |
56 | | - case ApplicationCommandType.ChatInput: { |
57 | | - const chatInputCmd = app.chatInputCommands.get(interaction.data.name); |
| 58 | + switch (interaction.data.type) { |
| 59 | + case ApplicationCommandType.ChatInput: { |
| 60 | + const chatInputCmd = app.chatInputCommands.get(interaction.data.name); |
58 | 61 |
|
59 | | - if (!chatInputCmd) return log("Red", `Command ${interaction.data.name} not found`); |
| 62 | + if (!chatInputCmd) return log("Red", `Command ${interaction.data.name} not found`); |
60 | 63 |
|
61 | | - log("White", [ |
62 | | - `\x1b[32m${(interaction.member ?? interaction).user!.username}\x1b[37m used `, |
63 | | - `/${interaction.data.name} ${options.getSubcommand(false) ?? ""}\x1b[37m in `, |
64 | | - `#${interaction.channel?.name ?? interaction.channel.id}` |
65 | | - ].join("\x1b[32m")); |
| 64 | + log("White", [ |
| 65 | + `\x1b[32m${(interaction.member ?? interaction).user!.username}\x1b[37m used `, |
| 66 | + `/${interaction.data.name} ${options.getSubcommand(false) ?? ""}\x1b[37m in `, |
| 67 | + `#${interaction.channel?.name ?? interaction.channel.id}` |
| 68 | + ].join("\x1b[32m")); |
66 | 69 |
|
67 | | - await chatInputCmd.run(app, interaction as APIChatInputApplicationCommandInteraction, options); |
68 | | - break; |
69 | | - } |
70 | | - default: { |
71 | | - const contextMenuCmd = app.contextMenuCommands.get(interaction.data.name); |
| 70 | + await chatInputCmd.run(app, interaction as APIChatInputApplicationCommandInteraction, options); |
| 71 | + break; |
| 72 | + } |
| 73 | + default: { |
| 74 | + const contextMenuCmd = app.contextMenuCommands.get(interaction.data.name); |
72 | 75 |
|
73 | | - if (!contextMenuCmd) return log("Red", `Command ${interaction.data.name} not found`); |
| 76 | + if (!contextMenuCmd) return log("Red", `Command ${interaction.data.name} not found`); |
74 | 77 |
|
75 | | - log("White", [ |
76 | | - `\x1b[32m${(interaction.member ?? interaction).user!.username}\x1b[37m used `, |
77 | | - `${interaction.data.name}\x1b[37m in `, |
78 | | - `#${interaction.channel.name ?? interaction.channel.id}` |
79 | | - ].join("\x1b[32m")); |
| 78 | + log("White", [ |
| 79 | + `\x1b[32m${(interaction.member ?? interaction).user!.username}\x1b[37m used `, |
| 80 | + `${interaction.data.name}\x1b[37m in `, |
| 81 | + `#${interaction.channel.name ?? interaction.channel.id}` |
| 82 | + ].join("\x1b[32m")); |
80 | 83 |
|
81 | | - await contextMenuCmd.run(app, interaction as APIContextMenuInteraction, options); |
82 | | - break; |
| 84 | + await contextMenuCmd.run(app, interaction as APIContextMenuInteraction, options); |
| 85 | + break; |
| 86 | + } |
83 | 87 | } |
84 | | - } |
85 | 88 |
|
86 | | - break; |
| 89 | + break; |
| 90 | + } |
| 91 | + default: |
| 92 | + log("Yellow", `Interaction type ${interaction.type} not implemented`); |
| 93 | + break; |
87 | 94 | } |
88 | | - case InteractionType.MessageComponent: |
89 | | - log("Yellow", "MessageComponent not implemented"); |
90 | | - break; |
91 | | - case InteractionType.ApplicationCommandAutocomplete: |
92 | | - log("Yellow", "ApplicationCommandAutocomplete not implemented"); |
93 | | - break; |
94 | | - case InteractionType.ModalSubmit: |
95 | | - log("Yellow", "ModalSubmit not implemented"); |
96 | | - break; |
97 | | - } |
98 | | -}).listen(+process.env.PORT!, process.env.HOSTNAME!, () => log("Blue", `Live on port \x1b[33m${process.env.PORT}\x1b[34m`)); |
| 95 | + }) |
| 96 | + .listen(parseInt(process.env.PORT!, 10)); |
| 97 | + |
| 98 | +log("Blue", `Live on port \x1b[33m${process.env.PORT}\x1b[34m`); |
99 | 99 |
|
100 | | -process.on("uncaughtException", console.log); |
| 100 | +process.on("uncaughtException", console.error); |
0 commit comments