aboutsummaryrefslogtreecommitdiff
path: root/command_impls.js
blob: 8e2cf4507a9b3b28e354721036d2fad3fd1a1969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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]");
}