diff options
author | jacob janzen <53062115+JacobJanzen@users.noreply.github.com> | 2024-12-11 21:40:39 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 21:40:39 -0600 |
commit | c25197dbe7a054022739190e41c12d09e79f4c04 (patch) | |
tree | 272cb9caf95933c49102a6711827c2a74596f381 /app.js | |
parent | 36066ad3d8d92855bbfdf4273a53066c6092fa45 (diff) |
Add Buttons; Remove Unschedule Command (#5)
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -6,13 +6,7 @@ import { verifyKeyMiddleware, } from "discord-interactions"; import { Client, GatewayIntentBits, ActivityType } from "discord.js"; -import { - blep, - help, - pet, - schedule_message, - unschedule_message, -} from "./command_impls.js"; +import { blep, help, pet, schedule_message } from "./command_impls.js"; import { MessageSchedule } from "./message-scheduler.js"; class State { @@ -34,9 +28,6 @@ function handle_application_command(state, data, channel_id) { options[1].value, ); - case "unschedule_message": - return unschedule_message(state, options[0].value); - case "pet": return pet(state); @@ -52,6 +43,20 @@ function handle_application_command(state, data, channel_id) { } } +function handle_button_press(state, data) { + if (data.custom_id.startsWith("stop-")) { + state.schedule.unschedule(data.custom_id.slice(5)); + + return state.res.send({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: "no longer sending this message", + }, + }); + } + return res.status(400).json({ error: "unknown command" }); +} + function main() { const state = new State(); @@ -86,6 +91,8 @@ function main() { return res.send({ type: InteractionResponseType.PONG }); case InteractionType.APPLICATION_COMMAND: return handle_application_command(state, data, channel_id); + case InteractionType.MESSAGE_COMPONENT: + return handle_button_press(state, data); default: console.error("unknown interaction type", type); return res |