36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
|
import { generateDiscordMessage, safeParseInput } from "../lib/dice";
|
|
|
|
export const data = new SlashCommandBuilder()
|
|
.setName("roll")
|
|
.addStringOption(option =>
|
|
option.setName("input")
|
|
.setDescription("The expression to roll")
|
|
.setRequired(true))
|
|
.setDescription("Rolls dice using hallowed arc syntax");
|
|
|
|
export async function execute(interaction: CommandInteraction) {
|
|
if (!interaction.isCommand()) return;
|
|
|
|
const { options } = interaction;
|
|
const input = options.get('input', true)?.value as string;
|
|
|
|
let result = safeParseInput(input);
|
|
if (result === null) {
|
|
await interaction.reply("Invalid input. Please provide a valid expression.");
|
|
return;
|
|
}
|
|
|
|
if (!Array.isArray(result)) {
|
|
result = [result];
|
|
}
|
|
|
|
const response = generateDiscordMessage(result);
|
|
|
|
if (response.length > 2000) {
|
|
await interaction.reply("stop that.\n-# (The result is too long to display in a single message. Please try a smaller input.)");
|
|
return;
|
|
}
|
|
|
|
await interaction.reply(response);
|
|
} |