aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorjacob janzen <53062115+JacobJanzen@users.noreply.github.com>2024-12-11 21:40:39 -0600
committerGitHub <noreply@github.com>2024-12-11 21:40:39 -0600
commitc25197dbe7a054022739190e41c12d09e79f4c04 (patch)
tree272cb9caf95933c49102a6711827c2a74596f381 /app.js
parent36066ad3d8d92855bbfdf4273a53066c6092fa45 (diff)
Add Buttons; Remove Unschedule Command (#5)
Diffstat (limited to 'app.js')
-rw-r--r--app.js27
1 files changed, 17 insertions, 10 deletions
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