From ee29d99139f54f04a944c6abea11214c012f7607 Mon Sep 17 00:00:00 2001 From: twlite <46562212+twlite@users.noreply.github.com> Date: Sat, 14 Jun 2025 16:45:18 +0545 Subject: [PATCH] feat: add executeAI function to process Discord messages and refine message handling in AiPlugin --- packages/ai/src/index.ts | 16 ++++++++++++++++ packages/ai/src/plugin.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/ai/src/index.ts b/packages/ai/src/index.ts index 2db1fd0b..dd432023 100644 --- a/packages/ai/src/index.ts +++ b/packages/ai/src/index.ts @@ -3,6 +3,7 @@ import { AiPlugin } from './plugin'; import { AiPluginOptions } from './types'; import { getAiWorkerContext } from './ai-context-worker'; import { getCommandKit } from 'commandkit'; +import type { Message } from 'discord.js'; /** * Retrieves the AI context. @@ -28,6 +29,21 @@ export function useAI() { return aiPlugin; } +/** + * Executes an AI command. + * @param message The message to execute the AI command on + * @example + * ```ts + * const message = await getMessageSomehow(); + * // use AI to process the message + * await executeAI(message); + * ``` + */ +export function executeAI(message: Message): Promise { + const aiPlugin = useAI(); + return aiPlugin.executeAI(message); +} + /** * Defines the AI plugin for the application. * @param options The options for the AI plugin diff --git a/packages/ai/src/plugin.ts b/packages/ai/src/plugin.ts index 16365927..f2c73032 100644 --- a/packages/ai/src/plugin.ts +++ b/packages/ai/src/plugin.ts @@ -68,7 +68,7 @@ export class AiPlugin extends RuntimePlugin { commandkit: CommandKit, message: Message, ): Promise { - if (message.author.bot || !Object.keys(this.toolsRecord).length) return; + if (message.author.bot) return; const { messageFilter, selectAiModel,