waengine 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +911 -0
- package/examples/easy-bot-examples.js +186 -0
- package/examples/multi-device-example.js +253 -0
- package/examples/quick-start.js +10 -0
- package/examples/simple-multi-device.js +42 -0
- package/package.json +67 -0
- package/src/client.js +412 -0
- package/src/core.js +79 -0
- package/src/device-manager.js +404 -0
- package/src/easy-bot.js +744 -0
- package/src/groups.js +156 -0
- package/src/index.js +6 -0
- package/src/message.js +628 -0
- package/src/messages.js +80 -0
- package/src/multi-client.js +374 -0
- package/src/qr.js +65 -0
- package/src/utils.js +0 -0
package/src/groups.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Groups-Klasse mit deinen eigenen Funktionen
|
|
2
|
+
|
|
3
|
+
export class Groups {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// ===== GET FUNCTIONS =====
|
|
9
|
+
|
|
10
|
+
async GroupMetadata(groupId) {
|
|
11
|
+
if (!this.client.isConnected) {
|
|
12
|
+
throw new Error('Not connected to WhatsApp');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return await this.client.socket.groupMetadata(groupId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async GroupParticipants(groupId) {
|
|
19
|
+
const metadata = await this.GroupMetadata(groupId);
|
|
20
|
+
return metadata.participants;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async GroupAdmins(groupId) {
|
|
24
|
+
const participants = await this.GroupParticipants(groupId);
|
|
25
|
+
return participants.filter(p => p.admin === 'admin' || p.admin === 'superadmin');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async GroupOwner(groupId) {
|
|
29
|
+
const participants = await this.GroupParticipants(groupId);
|
|
30
|
+
return participants.find(p => p.admin === 'superadmin');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ===== ADD FUNCTIONS =====
|
|
34
|
+
|
|
35
|
+
async user(groupId, users, mentions = []) {
|
|
36
|
+
if (!this.client.isConnected) {
|
|
37
|
+
throw new Error('Not connected to WhatsApp');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = await this.client.socket.groupParticipantsUpdate(groupId, users, 'add');
|
|
41
|
+
|
|
42
|
+
// Optional: Willkommensnachricht mit Mentions
|
|
43
|
+
if (mentions.length > 0) {
|
|
44
|
+
const welcomeText = `Willkommen in der Gruppe! ${mentions.map(id => `@${id.split('@')[0]}`).join(' ')}`;
|
|
45
|
+
await this.client.socket.sendMessage(groupId, {
|
|
46
|
+
text: welcomeText,
|
|
47
|
+
mentions: mentions
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ===== KICK FUNCTIONS =====
|
|
55
|
+
|
|
56
|
+
async user(groupId, users, mentions = []) {
|
|
57
|
+
if (!this.client.isConnected) {
|
|
58
|
+
throw new Error('Not connected to WhatsApp');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = await this.client.socket.groupParticipantsUpdate(groupId, users, 'remove');
|
|
62
|
+
|
|
63
|
+
// Optional: Nachricht mit Mentions
|
|
64
|
+
if (mentions.length > 0) {
|
|
65
|
+
const kickText = `${mentions.map(id => `@${id.split('@')[0]}`).join(' ')} wurde(n) aus der Gruppe entfernt.`;
|
|
66
|
+
await this.client.socket.sendMessage(groupId, {
|
|
67
|
+
text: kickText,
|
|
68
|
+
mentions: mentions
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ===== PROMOTE FUNCTIONS =====
|
|
76
|
+
|
|
77
|
+
async user(groupId, users, mentions = []) {
|
|
78
|
+
if (!this.client.isConnected) {
|
|
79
|
+
throw new Error('Not connected to WhatsApp');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result = await this.client.socket.groupParticipantsUpdate(groupId, users, 'promote');
|
|
83
|
+
|
|
84
|
+
// Optional: Nachricht mit Mentions
|
|
85
|
+
if (mentions.length > 0) {
|
|
86
|
+
const promoteText = `🎉 ${mentions.map(id => `@${id.split('@')[0]}`).join(' ')} wurde(n) zum Admin befördert!`;
|
|
87
|
+
await this.client.socket.sendMessage(groupId, {
|
|
88
|
+
text: promoteText,
|
|
89
|
+
mentions: mentions
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ===== DEMOTE FUNCTIONS =====
|
|
97
|
+
|
|
98
|
+
async user(groupId, users, mentions = []) {
|
|
99
|
+
if (!this.client.isConnected) {
|
|
100
|
+
throw new Error('Not connected to WhatsApp');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const result = await this.client.socket.groupParticipantsUpdate(groupId, users, 'demote');
|
|
104
|
+
|
|
105
|
+
// Optional: Nachricht mit Mentions
|
|
106
|
+
if (mentions.length > 0) {
|
|
107
|
+
const demoteText = `${mentions.map(id => `@${id.split('@')[0]}`).join(' ')} ist nicht mehr Admin.`;
|
|
108
|
+
await this.client.socket.sendMessage(groupId, {
|
|
109
|
+
text: demoteText,
|
|
110
|
+
mentions: mentions
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ===== GROUP SETTINGS =====
|
|
118
|
+
|
|
119
|
+
async updateName(groupId, name) {
|
|
120
|
+
return await this.client.socket.groupUpdateSubject(groupId, name);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async updateDescription(groupId, description) {
|
|
124
|
+
return await this.client.socket.groupUpdateDescription(groupId, description);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async updatePicture(groupId, imagePath) {
|
|
128
|
+
return await this.client.socket.updateProfilePicture(groupId, { url: imagePath });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async leave(groupId) {
|
|
132
|
+
return await this.client.socket.groupLeave(groupId);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ===== UTILITY FUNCTIONS =====
|
|
136
|
+
|
|
137
|
+
async isUserAdmin(groupId, userJid) {
|
|
138
|
+
const admins = await this.GroupAdmins(groupId);
|
|
139
|
+
return admins.some(admin => admin.id === userJid);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async isUserOwner(groupId, userJid) {
|
|
143
|
+
const owner = await this.GroupOwner(groupId);
|
|
144
|
+
return owner?.id === userJid;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async getUserRole(groupId, userJid) {
|
|
148
|
+
const participants = await this.GroupParticipants(groupId);
|
|
149
|
+
const user = participants.find(p => p.id === userJid);
|
|
150
|
+
|
|
151
|
+
if (!user) return 'not_member';
|
|
152
|
+
if (user.admin === 'superadmin') return 'owner';
|
|
153
|
+
if (user.admin === 'admin') return 'admin';
|
|
154
|
+
return 'member';
|
|
155
|
+
}
|
|
156
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { WhatsAppClient } from "./client.js";
|
|
2
|
+
export { MultiWhatsAppClient } from "./multi-client.js";
|
|
3
|
+
export { DeviceManager } from "./device-manager.js";
|
|
4
|
+
export { EasyBot, createBot, createMultiBot, quickBot, bot, multiBot } from "./easy-bot.js";
|
|
5
|
+
export { generateQRCode } from "./qr.js";
|
|
6
|
+
export { Message } from "./message.js";
|