From c25197dbe7a054022739190e41c12d09e79f4c04 Mon Sep 17 00:00:00 2001 From: jacob janzen <53062115+JacobJanzen@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:40:39 -0600 Subject: Add Buttons; Remove Unschedule Command (#5) --- app.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index f445a8f..5828b31 100644 --- a/app.js +++ b/app.js @@ -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 -- cgit v1.2.3