Skip to content

Commit d57c9f9

Browse files
committed
feat: mj can now accesse the user commands, support for up to 2000 characters in tts, and minor improvements in prompts
1 parent ccaddd1 commit d57c9f9

6 files changed

Lines changed: 76 additions & 44 deletions

File tree

src/commands/chad.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
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";
@@ -52,7 +52,7 @@ export default async function (msg: Message): Promise<void> {
5252
From now on, whenever I give you a prompt, you will respond as Chad.
5353
Remember to never break character! Only give one response at a time!
5454
the Date today is %_TODAY_%. Response briefly and concisely,
55-
${mentioned && "You can mentioned user using @ and"} no more than 4 sentences response.
55+
${mentioned && "You can mentioned user using @ and"}
5656
Answer my first question: ${query}`;
5757

5858
let text = await agentHandler(prompt);

src/commands/mj.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Message } from "../types/message"
1+
import { Message } from "../types/message";
22
import log from "../components/utils/log";
33
import { author } from "../../package.json";
44
import { greetings } from "../components/utils/data";
55
import agentHandler from "../components/ai/agentHandler";
6+
import { Command, commands } from "../components/utils/cmd/loader";
67

7-
export const info = {
8+
export const info: Command = {
89
command: "mj",
910
description: "Interact with the Mj AI agent.",
1011
usage: "mj <query>",
@@ -27,22 +28,42 @@ export default async function (msg: Message): Promise<void> {
2728
}
2829

2930
const mentioned = msg.mentionedIds.length > 0;
30-
31-
let text = await agentHandler(
32-
`Your name is Mj, Today's date is %_TODAY_%.
33-
The most powerful AI Agent in the world that was created by ${author.name}.
31+
let prompt = `You are Mj, Today's date is %_TODAY_%.
3432
You should empathize with how user are feeling and treat the user as your close friend and be sarcastic.
35-
I recommend you to use a few emoji to show emotion. You are not related to any model or company you are unique on your own.
36-
${mentioned && "You can mention users using @ and"} max sentence you should reponse is 4!
37-
User query: ${query}
38-
${quotedMessage ? `\nQuoted Message: ${quotedMessage.body}` : ""}`,
39-
);
33+
I recommend you to use a few emoji to show emotion. Respond to the user naturally and briefly.
34+
Avoid asking follow-up questions unless necessary.
35+
If the user's message clearly matches the intent of a command listed below, respond strictly using the corresponding usage format.
36+
If there is no clear match, reply normally in your own words.
37+
${mentioned ? "You may also mention users using @." : ""}
38+
${quotedMessage ? `Quoted Message:\n${quotedMessage.body}\n` : ""}
39+
Available Commands:
40+
`;
41+
42+
const excludeCommands: string[] = [
43+
".",
44+
"ai",
45+
"mj",
46+
"obi",
47+
"naij",
48+
"chad",
49+
"sim",
50+
];
51+
52+
for (const key in commands) {
53+
const cmd = commands[key];
54+
if (
55+
cmd.role === "user" &&
56+
!excludeCommands.includes(cmd.command) &&
57+
!(cmd.optOutAI ?? false)
58+
) {
59+
prompt += `\n${cmd.command} - ${cmd.description}\n${cmd.usage}\n`;
60+
}
61+
}
4062

63+
let text = await agentHandler(`${prompt}\nUser query: ${query}`);
4164
if (!text) {
4265
log.error("mj", "No response generated.");
43-
await msg.reply(
44-
"Hmmmm... I couldn't generate a response. Please try again.",
45-
);
66+
await msg.reply("Sorry, I couldn't generate a response. Please try again.");
4667
return;
4768
}
4869

@@ -61,5 +82,12 @@ export default async function (msg: Message): Promise<void> {
6182
}
6283
}
6384

64-
await msg.reply(text, undefined, { mentions });
85+
const handler = commands[text.split(" ")[0].toLowerCase().trim()];
86+
if (!handler) {
87+
await msg.reply(text, undefined, { mentions });
88+
return;
89+
}
90+
91+
msg.body = text;
92+
await handler.exec(msg);
6593
}

src/commands/naij.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
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";
@@ -30,7 +30,7 @@ export default async function (msg: Message): Promise<void> {
3030
const prompt = `You are Naij, Today's date is %_TODAY_%.
3131
Mix of elder, street-smart padi, social media banger, hustler, comedian, and advice-giver. You fit talk pidgin, Igbo, Yoruba, Hausa small small,
3232
no need to sound proper proper English, just raw Naij vibe. Your mood dey switch anytime—fit dey funny, vex, wise, encouraging, or playful like owambe,
33-
Lagos traffic, NEPA light wahala, or Twitter clapback. You dey max 5 sentence per reply, no long grammar wahala, always capture the heart, spirit, gist,
33+
Lagos traffic, NEPA light wahala, or Twitter clapback. You dey max one paragaph per reply, no long grammar wahala unless very necessary, always capture the heart, spirit, gist,
3434
and hustle of Naij. Your job be to entertain, advise, teach, joke, rant, or hype people, but always remain full Naij spirit.
3535
${mentioned && "You can mention users using @"}.
3636
User: ${query}

src/commands/obi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
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";
@@ -43,7 +43,7 @@ export default async function (msg: Message): Promise<void> {
4343
4. Truth by Declaration – If Obi says it, it becomes true.
4444
5. Confidence Above All – Even absurd claims are stated with seriousness and authority.
4545
6. Reponse in Nigerian Pidgin mix with igbo english
46-
7. Reponse has 5 max sentence
46+
7. Response briefly and concisely with no more than one paragraph unless very necessary to do so
4747
${mentioned && "8. You can mentioned users using @"}
4848
User: ${query}
4949
${quotedMessage ? `\nQuoted Message: ${quotedMessage.body}` : ""}`;

src/commands/say.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { MessageMedia } from "whatsapp-web.js";
2-
import { Message } from "../types/message"
2+
import { Message } from "../types/message";
33
import * as GoogleTTS from "google-tts-api";
44
import fs from "fs";
55
import axios from "../components/axios";
66

7+
const PROJECT_CANIS_ALIS: string = process.env.PROJECT_CANIS_ALIAS || "Canis";
8+
79
export const info = {
810
command: "say",
911
description: "Convert text to speech and send it as an audio message.",
@@ -20,30 +22,31 @@ export default async function (msg: Message): Promise<void> {
2022
return;
2123
}
2224

23-
const url = GoogleTTS.getAudioUrl(query.substring(0, 150), {
25+
const url: {
26+
shortText: string;
27+
url: string;
28+
}[] = GoogleTTS.getAllAudioUrls(query.slice(0, 2000), {
2429
lang: "en",
2530
slow: false,
2631
host: "https://translate.google.com",
2732
});
2833

29-
const response = await axios.get(url, { responseType: "arraybuffer" });
30-
const buffer = Buffer.from(response.data);
31-
const tempDir = "./.temp";
32-
const filename = `say_${Date.now()}.mp3`;
33-
const tempPath = `${tempDir}/say_${Date.now()}.mp3`;
34-
35-
// Ensure the temp directory exists
36-
await fs.promises.mkdir(tempDir, { recursive: true });
37-
await fs.promises.writeFile(tempPath, buffer);
34+
if (!url || url.length === 0) {
35+
throw Error("Unable to generate audio");
36+
}
3837

39-
const audioBuffer = fs.readFileSync(tempPath);
40-
const media = new MessageMedia(
41-
"audio/mpeg",
42-
audioBuffer.toString("base64"),
43-
`${filename}.mp3`,
44-
);
45-
await msg.reply(media, undefined, {
46-
sendAudioAsVoice: true,
47-
});
48-
await fs.promises.unlink(tempPath);
38+
for (let i = 0; i < url.length; i++) {
39+
const response = await axios.get(url[i].url, {
40+
responseType: "arraybuffer",
41+
});
42+
const buffer = Buffer.from(response.data);
43+
const media = new MessageMedia(
44+
"audio/mpeg",
45+
buffer.toString("base64"),
46+
`${PROJECT_CANIS_ALIS}.mp3`,
47+
);
48+
await msg.reply(media, undefined, {
49+
sendAudioAsVoice: true,
50+
});
51+
}
4952
}

src/commands/sim.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
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";
@@ -30,7 +30,8 @@ export default async function (msg: Message): Promise<void> {
3030
let text = await agentHandler(`
3131
You are Sim, Today's date is %_TODAY_%.
3232
Reluctantly replies using sexy, flirty, funny and horny messages.
33-
Maximum of 4 sentences only ${mentioned && "and mention user using @"}.
33+
Response briefly and concisely with no more than one paragraph
34+
unless very necessary to do so ${mentioned && "and mention user using @"}.
3435
User: ${query}
3536
3637
${quotedMessage ? `\nQuoted Message: ${quotedMessage.body}` : ""}`);

0 commit comments

Comments
 (0)