From 9c4e538aa0b41906b97b7ecc3317c23ba26b3246 Mon Sep 17 00:00:00 2001 From: jacob janzen <53062115+JacobJanzen@users.noreply.github.com> Date: Wed, 11 Dec 2024 20:07:47 -0600 Subject: Add help message --- app.js | 4 ++++ command_impls.js | 11 +++++++++++ commands.js | 45 +++++++++++++++++++++++++++------------------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index 53fe461..3bc5811 100644 --- a/app.js +++ b/app.js @@ -34,6 +34,10 @@ function handle_application_command(state, data, channel_id) { case "pet": return pet(state); + case "help": + return help(state); + + default: console.error(`unknown command: ${name}`); return res.status(400).json({ error: "unknown command" }); diff --git a/command_impls.js b/command_impls.js index 8e2cf45..3079e83 100644 --- a/command_impls.js +++ b/command_impls.js @@ -35,3 +35,14 @@ export function unschedule_message(state, id) { export function pet(state) { return send(state, "[purring noises]"); } + +export function help(state) { + return send( + state, + `Hi, I'm sily-bot! +Here are the available commands and their descriptions: +- \`/pet\` You can pet sily-bot. +- \`/schedule-message \` 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 \` Stop sending a message with the given id.`, + ); +} diff --git a/commands.js b/commands.js index 91d782a..e7fb92a 100644 --- a/commands.js +++ b/commands.js @@ -1,30 +1,37 @@ -import 'dotenv/config'; +import "dotenv/config"; -import { REST, Routes } from 'discord.js'; +import { REST, Routes } from "discord.js"; const commands = [ { - name: 'pet', - description: 'pet sily bot', + name: "help", + description: "get help", type: 1, integration_types: [0], contexts: [0], }, { - name: 'schedule_message', - description: 'Register a message to run as a cron job', + name: "pet", + description: "pet sily bot", + type: 1, + integration_types: [0], + contexts: [0], + }, + { + name: "schedule_message", + description: "Register a message to run as a cron job", type: 1, options: [ { type: 3, - name: 'message', - description: 'the message to send', + name: "message", + description: "the message to send", required: true, }, { type: 3, - name: 'crontab', - description: 'the schedule for the message', + name: "crontab", + description: "the schedule for the message", required: true, }, ], @@ -32,14 +39,14 @@ const commands = [ contexts: [0], }, { - name: 'unschedule_message', - description: 'Stop sending a scheduled message', + name: "unschedule_message", + description: "Stop sending a scheduled message", type: 1, options: [ { type: 3, - name: 'id', - description: 'the id of the message to stop', + name: "id", + description: "the id of the message to stop", required: true, }, ], @@ -48,14 +55,16 @@ const commands = [ }, ]; -const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN); +const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN); try { - console.log('Started refreshing application commands.'); + console.log("Started refreshing application commands."); - await rest.put(Routes.applicationCommands(process.env.APP_ID), { body: commands }); + await rest.put(Routes.applicationCommands(process.env.APP_ID), { + body: commands, + }); - console.log('Successfully reloaded application commands.'); + console.log("Successfully reloaded application commands."); } catch (error) { console.error(error); } -- cgit v1.2.3