Skip to content

Commit

Permalink
Merge pull request #69 from MikelCalvo/feature/skip_prefix_for_self
Browse files Browse the repository at this point in the history
Fixed skipPrefix for selfMessage
  • Loading branch information
Zain-ul-din authored Oct 27, 2024
2 parents f57e258 + ce42028 commit 80dc43e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/baileys/handlers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 10 additions & 1 deletion src/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 80dc43e

Please sign in to comment.