From ce42028d4073d5a1e63e2e2b92016a402a3bfdc4 Mon Sep 17 00:00:00 2001 From: Mikel Calvo Date: Sun, 27 Oct 2024 19:09:50 +0100 Subject: [PATCH] Fixed skipPrefix for selfMessage --- src/baileys/handlers/message.ts | 5 ++++- src/util/Util.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/baileys/handlers/message.ts b/src/baileys/handlers/message.ts index 4ab4e6c..a1a8c48 100644 --- a/src/baileys/handlers/message.ts +++ b/src/baileys/handlers/message.ts @@ -32,7 +32,10 @@ if (ENV.DALLE_ENABLED && ENV.OPENAI_ENABLED) { // handles message export async function handleMessage({ client, msg, metadata }: MessageHandlerParams) { - const modelInfo: ModelByPrefix | undefined = Util.getModelByPrefix(metadata.text); + const modelInfo: ModelByPrefix | undefined = Util.getModelByPrefix( + metadata.text, + metadata.fromMe + ); if (!modelInfo) { if (ENV.Debug) { console.log("[Debug] Model '" + modelInfo + "' not found"); diff --git a/src/util/Util.ts b/src/util/Util.ts index 7ddfd44..476603c 100644 --- a/src/util/Util.ts +++ b/src/util/Util.ts @@ -5,8 +5,17 @@ import config from '../whatsapp-ai.config'; export class Util { public static getModelByPrefix( - message: string + message: string, + fromMe: Boolean ): { modelName: AIModels; prefix: string } | undefined { + if (fromMe) { + const defaultModelName = config.prefix.defaultModel; + const defaultModel = config.models[defaultModelName]; + if (defaultModel && defaultModel.enable) { + return { modelName: defaultModelName as AIModels, prefix: defaultModel.prefix as string }; + } + } + for (let [modelName, model] of Object.entries(config.models)) { const currentModel = model as IModelConfig; if (!currentModel.enable) continue;