Skip to content

Commit b016236

Browse files
committed
feat: bug fixes and improvements
1 parent 3e8d79b commit b016236

6 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/commands/mute.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Message } from "../../types/message";
2+
import log from "../components/utils/log";
3+
4+
export const info = {
5+
command: "mute",
6+
description: "Mute this chat",
7+
usage: "mute",
8+
example: "mute",
9+
role: "admin",
10+
cooldown: 5000,
11+
};
12+
13+
export default async function (msg: Message) {
14+
if (!/^mute/i.test(msg.body)) return;
15+
16+
const chat = await msg.getChat();
17+
await chat.mute();
18+
19+
await msg.reply("This chat is now muted.");
20+
}

src/commands/play.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export default async function play(msg: Message) {
8080
writeStream.on("error", reject);
8181
});
8282

83+
// simulates audio recording
84+
const chat = await msg.getChat();
85+
chat.sendStateRecording();
86+
8387
await execPromise(
8488
`ffmpeg -y -i "${tempPath}" -vn -ar 44100 -ac 2 -b:a 192k "${tempPath}.mp3"`,
8589
);

src/commands/say.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MessageMedia } from "whatsapp-web.js";
2-
import { Message } from "../../types/message"
2+
import { Message } from "../../types/message";
33
import log from "../components/utils/log";
44
import * as GoogleTTS from "google-tts-api";
55
import fs from "fs";
@@ -28,6 +28,10 @@ export default async function (msg: Message) {
2828
host: "https://translate.google.com",
2929
});
3030

31+
// simulates audio recording
32+
const chat = await msg.getChat();
33+
chat.sendStateRecording();
34+
3135
const response = await axios.get(url, { responseType: "arraybuffer" });
3236
const buffer = Buffer.from(response.data);
3337
const tempDir = "./.temp";
@@ -42,7 +46,7 @@ export default async function (msg: Message) {
4246
const media = new MessageMedia(
4347
"audio/mpeg",
4448
audioBuffer.toString("base64"),
45-
`${filename}.mp3`
49+
`${filename}.mp3`,
4650
);
4751
await msg.reply(media, msg.from, {
4852
sendAudioAsVoice: true,

src/commands/stats.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export default async function (msg: Message) {
5353
blockUserCount,
5454
waStatus,
5555
waVersion,
56+
deviceCount,
57+
chats,
5658
] = await Promise.all([
5759
si.graphics(),
5860
si.osInfo(),
@@ -62,6 +64,8 @@ export default async function (msg: Message) {
6264
getBlockUserCount(),
6365
client.getState(),
6466
client.getWWebVersion(),
67+
client.getContactDeviceCount(msg.from),
68+
client.getChats(),
6569
]);
6670

6771
const statsMessage = `
@@ -91,6 +95,8 @@ export default async function (msg: Message) {
9195
9296
Status: ${waStatus}
9397
Version: ${waVersion}
98+
Devices: ${deviceCount}
99+
Chats: ${chats.length}
94100
95101
\`${PROJECT_CANIS_ALIAS}\`
96102

src/commands/unmute.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Message } from "../../types/message";
2+
import log from "../components/utils/log";
3+
4+
export const info = {
5+
command: "unmute",
6+
description: "Unmute this chat",
7+
usage: "unmute",
8+
example: "unmute",
9+
role: "admin",
10+
cooldown: 5000,
11+
};
12+
13+
export default async function (msg: Message) {
14+
if (!/^unmute/i.test(msg.body)) return;
15+
16+
const chat = await msg.getChat();
17+
await chat.unmute();
18+
19+
await msg.reply("This chat is now unmuted.");
20+
}

src/components/events/groups/join.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export default async function (notif: GroupNotification) {
3939
if (newMembers.length > 0) {
4040
await notif.reply(getMessage("welcome", `*${newMembers.join(", ")}*`));
4141
}
42+
43+
// mute the chat forever
44+
const chat = await notif.getChat();
45+
await chat.mute();
4246
} catch (err) {
4347
log.error("GroupJoin", "Failed to process group join event:", err);
4448
}

0 commit comments

Comments
 (0)