diff --git a/src/commands/char.ts b/src/commands/char.ts new file mode 100644 index 0000000..2030eef --- /dev/null +++ b/src/commands/char.ts @@ -0,0 +1,47 @@ +import { CacheType, Interaction } from "discord.js"; + +const COUNT = "COUNT"; + +export const charCommand = { + name: "text", + description: "Tools to work with characters / words", + options: [ + { + name: "operation", + description: "The type of operation to perform", + required: true, + type: 3, + choices: [{ name: "Count", value: COUNT }], + }, + { + name: "text", + description: "The text to operate on", + required: true, + type: 3, + }, + ], + + execute: async (interaction: Interaction) => { + if (!interaction.isCommand()) return; + + const { options } = interaction; + + const operationOption = options.get("operation"); + if (operationOption) { + const operation = operationOption.value as string; + + switch (operation) { + case COUNT: { + const text = options.get("text")?.value as string; + const charCount = text.length; + const wordCount = text.split(" ").length; + + await interaction.reply( + `Character count: ${charCount}\nWord count: ${wordCount}` + ); + break; + } + } + } + }, +}; diff --git a/src/commands/index.ts b/src/commands/index.ts index f79d638..a7be1e4 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,9 +1,16 @@ import { base64command } from "./base64"; +import { charCommand } from "./char"; import { generateCommand } from "./generate"; import { jsonCommand } from "./json"; import { timeCommand } from "./time"; -const commands = [base64command, generateCommand, jsonCommand, timeCommand]; +const commands = [ + base64command, + charCommand, + generateCommand, + jsonCommand, + timeCommand, +]; const botCommandsMap: { [key: string]: any } = {};