beniocord.js 2.0.6 → 2.0.7
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/Client.js +22 -14
- package/package.json +1 -1
- package/structures/MessageCollector.js +1 -1
package/Client.js
CHANGED
|
@@ -164,6 +164,8 @@ class Client extends EventEmitter {
|
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
await this._joinAllChannelRooms();
|
|
168
|
+
|
|
167
169
|
this.isReady = true;
|
|
168
170
|
this.emit("ready", this.user);
|
|
169
171
|
|
|
@@ -266,6 +268,20 @@ class Client extends EventEmitter {
|
|
|
266
268
|
});
|
|
267
269
|
}
|
|
268
270
|
|
|
271
|
+
async _joinAllChannelRooms() {
|
|
272
|
+
try {
|
|
273
|
+
const channels = await this.fetchChannels();
|
|
274
|
+
|
|
275
|
+
for (const channel of channels) {
|
|
276
|
+
if (this.socket && this.socket.connected) {
|
|
277
|
+
this.socket.emit('channel:join', { channelId: channel.id });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} catch (error) {
|
|
281
|
+
console.error('Erro ao entrar nas rooms dos canais:', error);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
269
285
|
/**
|
|
270
286
|
* Inicia o sistema de heartbeat
|
|
271
287
|
* @private
|
|
@@ -402,20 +418,17 @@ class Client extends EventEmitter {
|
|
|
402
418
|
data.member = member;
|
|
403
419
|
data.channel = channel;
|
|
404
420
|
|
|
405
|
-
// 🔥 Se EU fui adicionado ao canal
|
|
406
421
|
if (data.memberId === this.user?.id) {
|
|
407
|
-
// Adiciona o canal na cache se não existir
|
|
408
422
|
if (channel && !this.cache.channels.has(data.channelId)) {
|
|
409
423
|
this.cache.channels.set(data.channelId, channel);
|
|
410
424
|
}
|
|
411
425
|
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
if (this.socket && this.socket.connected) {
|
|
427
|
+
this.socket.emit('channel:join', { channelId: data.channelId });
|
|
428
|
+
}
|
|
414
429
|
}
|
|
415
430
|
|
|
416
|
-
// 🔥 Se o canal já existe na cache, adiciona o membro nele
|
|
417
431
|
if (channel && member) {
|
|
418
|
-
// Assumindo que o Channel tem uma lista/Map de membros
|
|
419
432
|
if (!channel.members) {
|
|
420
433
|
channel.members = new Map();
|
|
421
434
|
}
|
|
@@ -423,7 +436,6 @@ class Client extends EventEmitter {
|
|
|
423
436
|
}
|
|
424
437
|
|
|
425
438
|
this.emit('memberJoin', data);
|
|
426
|
-
console.log('join', data);
|
|
427
439
|
});
|
|
428
440
|
|
|
429
441
|
this.socket.on('member:leave', async (data) => {
|
|
@@ -437,22 +449,18 @@ class Client extends EventEmitter {
|
|
|
437
449
|
data.member = member;
|
|
438
450
|
data.channel = channel;
|
|
439
451
|
|
|
440
|
-
// 🔥 Se EU fui removido do canal
|
|
441
452
|
if (data.memberId === this.user?.id) {
|
|
442
|
-
// Remove o canal da cache
|
|
443
453
|
this.cache.channels.delete(data.channelId);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
454
|
+
if (this.socket && this.socket.connected) {
|
|
455
|
+
this.socket.emit('channel:leave', { channelId: data.channelId });
|
|
456
|
+
}
|
|
447
457
|
}
|
|
448
458
|
|
|
449
|
-
// 🔥 Se o canal existe na cache, remove o membro dele
|
|
450
459
|
if (channel && member && channel.members) {
|
|
451
460
|
channel.members.delete(member.id);
|
|
452
461
|
}
|
|
453
462
|
|
|
454
463
|
this.emit('memberLeave', data);
|
|
455
|
-
console.log('leave', data);
|
|
456
464
|
});
|
|
457
465
|
|
|
458
466
|
this.socket.on('channel:update', (data) => {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"socket.io-client": "^4.8.1"
|
|
5
5
|
},
|
|
6
6
|
"name": "beniocord.js",
|
|
7
|
-
"version": "2.0.
|
|
7
|
+
"version": "2.0.7",
|
|
8
8
|
"description": "Uma biblioteca leve e intuitiva para integração com APIs de bots em plataformas de mensagens, como Discord. Facilita o envio de mensagens, gerenciamento de canais e interação com usuários, proporcionando uma experiência de desenvolvimento ágil e eficiente.",
|
|
9
9
|
"main": "Client.js",
|
|
10
10
|
"devDependencies": {},
|