Skip to content

Commit 5b0c866

Browse files
committed
fix: client are not receiving messages and added echo command
1 parent 1897cbe commit 5b0c866

4 files changed

Lines changed: 98 additions & 39 deletions

File tree

package-lock.json

Lines changed: 39 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"systeminformation": "^5.27.11",
5858
"unbzip2-stream": "^1.4.3",
5959
"undici": "^7.16.0",
60-
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
60+
"whatsapp-web.js": "^1.34.6",
6161
"youtubei.js": "^16.0.1"
6262
},
6363
"devDependencies": {

src/commands/echo.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Message } from "../types/message";
2+
3+
export const info = {
4+
command: "echo",
5+
description: "Echo the user's message.",
6+
usage: "echo <count> <time> <message>",
7+
example: "echo 5 10s Hello, world!",
8+
role: "admin",
9+
cooldown: 5000,
10+
};
11+
12+
export default async function (msg: Message): Promise<void> {
13+
const args = msg.body.trim().split(" ").slice(1);
14+
if (args.length < 3) {
15+
await msg.reply(
16+
"Usage: echo <count> <time> <message>\nExample: echo 5 10s Hello, world!",
17+
);
18+
return;
19+
}
20+
21+
const count = parseInt(args[0], 10);
22+
const timeStr = args[1];
23+
const message = args.slice(2).join(" ");
24+
25+
if (isNaN(count) || count <= 0) {
26+
await msg.reply("Please provide a valid positive number for count.");
27+
return;
28+
}
29+
30+
const timeMatch = timeStr.match(/^(\d+)(s|m|h)$/);
31+
if (!timeMatch) {
32+
await msg.reply("Please provide a valid time format (e.g., 10s, 5m, 1h).");
33+
return;
34+
}
35+
36+
const timeValue = parseInt(timeMatch[1], 10);
37+
const timeUnit = timeMatch[2];
38+
let delay = 0;
39+
40+
switch (timeUnit) {
41+
case "s":
42+
delay = timeValue * 1000;
43+
break;
44+
case "m":
45+
delay = timeValue * 60 * 1000;
46+
break;
47+
case "h":
48+
delay = timeValue * 60 * 60 * 1000;
49+
break;
50+
}
51+
52+
for (let i = 0; i < count; i++) {
53+
setTimeout(async () => {
54+
await msg.reply(message);
55+
}, delay * i);
56+
}
57+
}

src/components/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function registerEvents(client: Client): void {
9191

9292
client.on("message_create", (msg: Message) => {
9393
CheckSpamLink(msg);
94+
console.log(JSON.stringify(msg))
9495
messageEvent(msg, "create");
9596
queue.add(() => DownloadMedia(msg));
9697
});

0 commit comments

Comments
 (0)