aboutsummaryrefslogtreecommitdiff
path: root/command_impls.js
diff options
context:
space:
mode:
Diffstat (limited to 'command_impls.js')
-rw-r--r--command_impls.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/command_impls.js b/command_impls.js
new file mode 100644
index 0000000..8e2cf45
--- /dev/null
+++ b/command_impls.js
@@ -0,0 +1,37 @@
+import { InteractionResponseType } from "discord-interactions";
+import { Message } from "./message-scheduler.js";
+
+function send(state, content) {
+ return state.res.send({
+ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
+ data: {
+ content: content,
+ },
+ });
+}
+
+export function schedule_message(state, msg, channel, crontab) {
+ const message = new Message(msg, channel, crontab);
+
+ const schedule_valid = state.schedule.schedule(message);
+
+ return send(
+ state,
+ schedule_valid
+ ? `registered message: "${msg}" with cron: "${crontab}" and id: "${message.id}"`
+ : "invalid cron",
+ );
+}
+
+export function unschedule_message(state, id) {
+ const unschedule_valid = state.schedule.unschedule(id);
+
+ return send(
+ state,
+ unschedule_valid ? `stopped job ${id}` : `no such job ${id}`,
+ );
+}
+
+export function pet(state) {
+ return send(state, "[purring noises]");
+}