Skip to content

Commit 5dfcdb3

Browse files
committed
chore: improve command documentation
1 parent e6b1968 commit 5dfcdb3

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/commands/ai.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Message } from "../types/message";
22
import log from "../components/utils/log";
33
import agentHandler from "../components/ai/agentHandler";
44
import { greetings } from "../components/utils/data";
5-
import { commands } from "../components/utils/cmd/loader";
5+
import { Command, commands } from "../components/utils/cmd/loader";
66

77
const PROJECT_CANIS_ALIS: string = process.env.PROJECT_CANIS_ALIAS || "Canis";
88

9-
export const info = {
9+
export const info: Command = {
1010
command: "ai",
1111
description: "Interact with the AI agent.",
1212
usage: "ai <query>",
@@ -42,7 +42,11 @@ export default async function (msg: Message): Promise<void> {
4242

4343
for (const key in commands) {
4444
const cmd = commands[key];
45-
if (cmd.role === "user" && !excludeAiCommands.includes(cmd.command)) {
45+
if (
46+
cmd.role === "user" &&
47+
!excludeAiCommands.includes(cmd.command) &&
48+
!(cmd.optOutAI ?? false)
49+
) {
4650
prompt += `\n${cmd.command} - ${cmd.description}\n${cmd.usage}\n`;
4751
}
4852
}

src/components/utils/cmd/loader.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,34 @@ const basePath = path.join(__dirname, "..", "..", "..", "commands");
1010
import * as Sentry from "@sentry/node";
1111

1212
export const commandDirs = [basePath, path.join(basePath, "private")];
13-
export const commands: Record<
14-
string,
15-
{
16-
command: string;
17-
description: string;
18-
usage: string;
19-
example: string;
20-
role: string;
21-
cooldown: number;
22-
exec: (msg: Message) => Promise<void>;
23-
}
24-
> = {};
13+
export interface Command {
14+
/** The actual command keyword the bot will listen for */
15+
command: string;
16+
17+
/** A brief description of what the command does */
18+
description: string;
19+
20+
/** How to use the command (syntax) */
21+
usage: string;
22+
23+
/** Example usage of the command */
24+
example: string;
25+
26+
/** Required role to use the command (e.g., 'admin', 'moderator') */
27+
role: string;
28+
29+
/** Cooldown in seconds before the command can be reused */
30+
cooldown: number;
31+
32+
/** Optional: set to true if you don't want AI to process this command */
33+
optOutAI?: boolean;
34+
}
35+
36+
interface InternalCommands extends Command {
37+
/** The function that will be executed when the command is called */
38+
exec: (msg: Message) => Promise<void>;
39+
}
40+
export const commands: Record<string, InternalCommands> = {};
2541

2642
async function ensureDependencies(
2743
dependencies: { name: string; version: string }[],

0 commit comments

Comments
 (0)