Skip to content

Commit

Permalink
feat: Added Command for Char / Word Count
Browse files Browse the repository at this point in the history
  • Loading branch information
bmonish committed May 21, 2024
1 parent fe9fe90 commit 30fdf59
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/commands/char.ts
Original file line number Diff line number Diff line change
@@ -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<CacheType>) => {
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;
}
}
}
},
};
9 changes: 8 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -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 } = {};

Expand Down

0 comments on commit 30fdf59

Please sign in to comment.