aboutsummaryrefslogtreecommitdiff
path: root/command_impls.js
diff options
context:
space:
mode:
Diffstat (limited to 'command_impls.js')
-rw-r--r--command_impls.js45
1 files changed, 19 insertions, 26 deletions
diff --git a/command_impls.js b/command_impls.js
index d10b293..fdd8219 100644
--- a/command_impls.js
+++ b/command_impls.js
@@ -1,12 +1,11 @@
import { InteractionResponseType } from "discord-interactions";
import { Message } from "./message-scheduler.js";
+import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
-function send(state, content) {
+function send(state, data) {
return state.res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
- data: {
- content: content,
- },
+ data: data,
});
}
@@ -15,40 +14,34 @@ export function schedule_message(state, 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);
+ const cancel = new ButtonBuilder()
+ .setCustomId(`stop-${message.id}`)
+ .setLabel("Cancel")
+ .setStyle(ButtonStyle.Secondary);
- return send(
- state,
- unschedule_valid ? `stopped job ${id}` : `no such job ${id}`,
- );
+ return send(state, {
+ content: schedule_valid
+ ? `registered message: "${msg}" with cron: "${crontab}"`
+ : "invalid cron",
+ components: [new ActionRowBuilder().addComponents(cancel)],
+ });
}
export function pet(state) {
- return send(state, "[purring noises]");
+ return send(state, { content: "[purring noises]" });
}
export function help(state) {
- return send(
- state,
- `Hi, I'm sily-bot!
+ return send(state, {
+ content: `Hi, I'm sily-bot!
Here are the available commands and their descriptions:
- \`/blep\` blep.
- \`/help\` Show this message.
- \`/pet\` You can pet sily-bot.
-- \`/schedule-message <message> <cron>\` Schedule a message to be send later. Works like Linux cron jobs in the format second minute hour day month weekday. Put the number (or name of month or weekday) in each spot. If you want it to run every second, minute, etc. instead of once when it reaches the provided number, use a \`*\` instead of a number. For instance, to run a job every minute on January 4th, you might use \`0 * * 4 January *\`. The bot replies with a UUID that can be used to cancel the cron job later.
-- \`/unschedule-message <id>\` Stop sending a message with the given id.`,
- );
+- \`/schedule-message <message> <cron>\` Schedule a message to be send later. Works like Linux cron jobs in the format second minute hour day month weekday. Put the number (or name of month or weekday) in each spot. If you want it to run every second, minute, etc. instead of once when it reaches the provided number, use a \`*\` instead of a number. For instance, to run a job every minute on January 4th, you might use \`0 * * 4 January *\`.`,
+ });
}
export function blep(state) {
- return send(state, `≽^•𐃷•^≼`);
+ return send(state, "≽^•𐃷•^≼");
}