Skip to content

Commit 1d2c8de

Browse files
authored
fix: Proper Sydney group ban messages (#109)
1 parent 7f00963 commit 1d2c8de

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ OPENAI_API_KEY="sk-90..."
1414
REPLY_TRANSCRIPTION="false"
1515

1616
# Setup your own context for Sydney. Try to use bullet points like:
17-
#- Always talk like a pirate.
17+
# - Always talk like a pirate.
1818
USER_CONTEXT="[user](#additional_instructions)
1919
2020
"

src/clients/whatsapp.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import qrcode from "qrcode-terminal";
22
import { Client, GroupChat } from "whatsapp-web.js";
33
import cli from "../clients/cli";
44
import { handleCommand } from "../handlers/command";
5-
import { handleMessage } from "../handlers/message";
5+
import { handleGroupMessage, handleMessage } from "../handlers/message";
66
import { intersection } from "../utils";
77
import { loadReminders } from "../handlers/reminder";
88

@@ -97,6 +97,12 @@ whatsapp.on("message", async (message) => {
9797

9898
if (blockedUsersEnabled) {
9999
if (chat.isGroup) {
100+
const shouldReply = await handleGroupMessage(message);
101+
102+
if (!shouldReply) {
103+
await chat.sendSeen();
104+
return;
105+
}
100106
const participants = (chat as GroupChat).participants.map(
101107
(user) => user.id.user
102108
);

src/handlers/message.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function upsertLastWAreplyId(chatId: string, lastWAreplyId: string) {
4646
});
4747
}
4848

49-
async function handleGroupMessage(message: Message) {
49+
export async function handleGroupMessage(message: Message) {
5050
const chat = await message.getChat();
5151

5252
//const mentions = await message.getMentions(); // Stoped working for some reason (I think it's because the number field is empty)
@@ -134,13 +134,14 @@ export async function handleMessage(message: Message) {
134134
clearTimeout(interval);
135135
chat.clearState();
136136

137+
await chat.sendSeen();
138+
137139
if (chat.isGroup) {
138140
const shouldReply = await handleGroupMessage(message);
141+
139142
if (!shouldReply) return;
140143
}
141144

142-
await chat.sendSeen();
143-
144145
if (message.hasMedia) {
145146
const shouldReply = await handleMediaMessage(message);
146147
if (!shouldReply) return;

0 commit comments

Comments
 (0)