From 9587ae4818ba05fbfc130b936528211f803fd44b Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:19:57 +0300 Subject: [PATCH 01/25] I guess its time to work on multiple rooms now --- chatBot/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index 6417cf4..c88d51b 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -42,7 +42,7 @@ loadCommands().then(commands => { if (message.type == "icon") return; console.log(message); - console.log(`Message received from ${message.name}@${peer} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); + console.log(`Message received from ${message.name}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); // Check if the message starts with a command prefix if (message.message.startsWith('!')) { -- 2.39.3 From 24101e5611588e9b36da2522131c1522dc66394c Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 22:55:32 +0300 Subject: [PATCH 02/25] Trying to make multiple rooms support. This is gonna be a bit of a hell lol. --- chatBot/commands/8ball.js | 2 +- chatBot/commands/hello.js | 2 +- chatBot/commands/ping.js | 2 +- chatBot/includes/client.js | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/chatBot/commands/8ball.js b/chatBot/commands/8ball.js index d9cb238..0fc287f 100644 --- a/chatBot/commands/8ball.js +++ b/chatBot/commands/8ball.js @@ -4,6 +4,6 @@ export default { handler: function(bot, args, message) { const responses = ['It is certain.', 'It is decidedly so.', 'Without a doubt.', 'Yes - definitely.', 'You may rely on it.', 'As I see it, yes.', 'Most likely.', 'Outlook good.', 'Yes.', 'Signs point to yes.', 'Reply hazy, try again.', 'Ask again later.', 'Better not tell you now.', 'Cannot predict now.', 'Concentrate and ask again.', 'Don\'t count on it.', 'My reply is no.', 'My sources say no.', 'Outlook not so good.', 'Very doubtful.']; const randomIndex = Math.floor(Math.random() * responses.length); - bot.sendMessage(responses[randomIndex]); + bot.sendMessage(message.peers, responses[randomIndex]); } }; \ No newline at end of file diff --git a/chatBot/commands/hello.js b/chatBot/commands/hello.js index 8bf16c2..1c0ee81 100644 --- a/chatBot/commands/hello.js +++ b/chatBot/commands/hello.js @@ -3,6 +3,6 @@ export default { description: 'Greet the user', handler: function(bot, args, message) { const userName = message.name; - bot.sendMessage(`Hello, ${userName}! How can I assist you today?`); + bot.sendMessage(message.peers, `Hello, ${userName}! How can I assist you today?`); } }; \ No newline at end of file diff --git a/chatBot/commands/ping.js b/chatBot/commands/ping.js index df71415..16f26a4 100644 --- a/chatBot/commands/ping.js +++ b/chatBot/commands/ping.js @@ -2,6 +2,6 @@ export default { handler: function(bot, args, message) { - bot.sendMessage('Pong!'); + bot.sendMessage(message.peers, 'Pong!'); } }; \ No newline at end of file diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 6df8ff4..2de7175 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -32,10 +32,11 @@ class Client extends EventEmitter { }); } - sendMessage(message) { + sendMessage(roomPeers, message) { console.log('Bot name:', this.botName); const timestamp = Date.now(); // Generate timestamp - const peers = [...this.swarm.connections]; + const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex'))); + console.log(`Sending message ${message} to peers ${peers}`) const data = JSON.stringify({name: this.botName, message, timestamp}); // Include timestamp for (const peer of peers) peer.write(data); } -- 2.39.3 From 165d2f0faab5f79d10f8eb4b746c97f133f548bf Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:07:54 +0300 Subject: [PATCH 03/25] Trying to fix a bug with message peers --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 4a8545c..b17b0cd 100644 --- a/app.js +++ b/app.js @@ -302,7 +302,7 @@ function sendMessage(e) { message, avatar: config.userAvatar, topic: b4a.toString(currentRoom.topic, 'hex'), - peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')), + peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).push(swarm.publicKey.toString('hex')), timestamp: Date.now(), readableTimestamp: new Date().toLocaleString(), // Added human-readable timestamp }); -- 2.39.3 From 805983e3f5936928a198b98e3e6d40e05896e5b0 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:14:26 +0300 Subject: [PATCH 04/25] Oops forgot about bot startup message. It doesnt work because there's no known peers yet --- chatBot/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index c88d51b..eda0d50 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -61,7 +61,7 @@ loadCommands().then(commands => { bot.on('onBotJoinRoom', () => { console.log("Bot is ready!"); - bot.sendMessage(process.env.ON_READY_MESSAGE); + // bot.sendMessage(process.env.ON_READY_MESSAGE); }); bot.joinChatRoom(process.env.LINKUP_ROOM_ID); -- 2.39.3 From 704f6ca0dc82295b4fe9d6b506089aea8498d5bf Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:17:34 +0300 Subject: [PATCH 05/25] Hmm how can i get publickey of the user sending info and not just peers who connected? --- app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index b17b0cd..5e95740 100644 --- a/app.js +++ b/app.js @@ -296,13 +296,15 @@ function sendMessage(e) { onMessageAdded(config.userName, message, config.userAvatar); + console.log(swarm.keyPair); + console.log("swarm:", swarm); const messageObj = JSON.stringify({ type: 'message', name: config.userName, message, avatar: config.userAvatar, topic: b4a.toString(currentRoom.topic, 'hex'), - peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).push(swarm.publicKey.toString('hex')), + peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')), timestamp: Date.now(), readableTimestamp: new Date().toLocaleString(), // Added human-readable timestamp }); -- 2.39.3 From 961599f366491d5962b6411d5eb8b90cf5cd2fba Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:19:36 +0300 Subject: [PATCH 06/25] I might've fix sending all 'peers' lol --- app.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app.js b/app.js index 5e95740..9ab3779 100644 --- a/app.js +++ b/app.js @@ -296,15 +296,13 @@ function sendMessage(e) { onMessageAdded(config.userName, message, config.userAvatar); - console.log(swarm.keyPair); - console.log("swarm:", swarm); const messageObj = JSON.stringify({ type: 'message', name: config.userName, message, avatar: config.userAvatar, topic: b4a.toString(currentRoom.topic, 'hex'), - peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')), + peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).push(swarm.keyPair.publicKey.toString('hex')), timestamp: Date.now(), readableTimestamp: new Date().toLocaleString(), // Added human-readable timestamp }); -- 2.39.3 From d9dbdf440142b3350000f5bd06584847e3ded6a7 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:22:06 +0300 Subject: [PATCH 07/25] Oh i actually broke it because push returns length and not array itself :skull: --- app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 9ab3779..a7e629a 100644 --- a/app.js +++ b/app.js @@ -296,13 +296,17 @@ function sendMessage(e) { onMessageAdded(config.userName, message, config.userAvatar); + let peersPublicKeys = []; + peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex'))); + peersPublicKeys.push(swarm.keyPair.publicKey.toString('hex')); + const messageObj = JSON.stringify({ type: 'message', name: config.userName, message, avatar: config.userAvatar, topic: b4a.toString(currentRoom.topic, 'hex'), - peers: [...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).push(swarm.keyPair.publicKey.toString('hex')), + peers: peersPublicKeys, timestamp: Date.now(), readableTimestamp: new Date().toLocaleString(), // Added human-readable timestamp }); -- 2.39.3 From 8788adbc2b94336408003f899aeddfac673781e9 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:28:18 +0300 Subject: [PATCH 08/25] Fixed sending ON_READY_MESSAGE --- chatBot/bot.js | 2 +- chatBot/includes/client.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index eda0d50..b2844c3 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -61,7 +61,7 @@ loadCommands().then(commands => { bot.on('onBotJoinRoom', () => { console.log("Bot is ready!"); - // bot.sendMessage(process.env.ON_READY_MESSAGE); + bot.sendMessageToAll(process.env.ON_READY_MESSAGE); }); bot.joinChatRoom(process.env.LINKUP_ROOM_ID); diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 2de7175..09964f5 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -35,8 +35,15 @@ class Client extends EventEmitter { sendMessage(roomPeers, message) { console.log('Bot name:', this.botName); const timestamp = Date.now(); // Generate timestamp - const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex'))); - console.log(`Sending message ${message} to peers ${peers}`) + const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex'))); // We remove all the peers that arent included in a room + const data = JSON.stringify({name: this.botName, message, timestamp}); // Include timestamp + for (const peer of peers) peer.write(data); + } + + sendMessageToAll(message) { + console.log('Bot name:', this.botName); + const timestamp = Date.now(); // Generate timestamp + const peers = [...this.swarm.connections] const data = JSON.stringify({name: this.botName, message, timestamp}); // Include timestamp for (const peer of peers) peer.write(data); } -- 2.39.3 From 4cfae430b2859c5ea6a8d13b883b71431529eb69 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:34:21 +0300 Subject: [PATCH 09/25] Started working on ChatRoom class --- chatBot/includes/chatroom.js | 10 ++++++++++ chatBot/includes/client.js | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 chatBot/includes/chatroom.js diff --git a/chatBot/includes/chatroom.js b/chatBot/includes/chatroom.js new file mode 100644 index 0000000..89b2afe --- /dev/null +++ b/chatBot/includes/chatroom.js @@ -0,0 +1,10 @@ +class ChatRoom { + public ChatRoom(topic, peers) { + this.topic = topic; + this.peers = peers; + } + + +} + +export default ChatRoom; \ No newline at end of file diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 09964f5..26de967 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -21,6 +21,8 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); + console.log([...this.swarm.connections]) + process.exit(-1); }); } -- 2.39.3 From fda25abe8cf5dc4248f0900986e75dd5a1c1c8b3 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:34:57 +0300 Subject: [PATCH 10/25] Oops debugging didnt go as planned lol --- chatBot/includes/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 26de967..2842096 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -21,8 +21,8 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); - console.log([...this.swarm.connections]) - process.exit(-1); + console.log([...this.swarm.connections]); + if(this.swarm.connections.size > 0) process.exit(-1); }); } -- 2.39.3 From 7399585d9e21061d76541eb03765baf629596487 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:38:50 +0300 Subject: [PATCH 11/25] Trying to find a way to check which topic each pear is from --- chatBot/includes/client.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 2842096..c9813c6 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -21,8 +21,10 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); - console.log([...this.swarm.connections]); - if(this.swarm.connections.size > 0) process.exit(-1); + if(this.swarm.connections.size > 0) { + console.log([...this.swarm]); + process.exit(-1); + } }); } -- 2.39.3 From 6980520a85b65b656c7a042311696258260a9508 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:40:57 +0300 Subject: [PATCH 12/25] Lol i tried to iterate over not-iterable object --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index c9813c6..e21168c 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,7 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - console.log([...this.swarm]); + console.log([this.swarm]); process.exit(-1); } }); -- 2.39.3 From 7751d03b578ce242ea17125a42a840b14ef6e2ed Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:44:32 +0300 Subject: [PATCH 13/25] Found something interesting called 'swarm.peers' --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index e21168c..e9f77af 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,7 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - console.log([this.swarm]); + console.log([...this.swarm.peers]); process.exit(-1); } }); -- 2.39.3 From d1ee697c84c7e476cab94160d82dca0848e490b7 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:48:24 +0300 Subject: [PATCH 14/25] There's something even more interesting called 'peerInfo.topics' lol. So bad it has no good docs and i have to do this stuff to learn more --- chatBot/includes/client.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index e9f77af..75e7b79 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,9 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - console.log([...this.swarm.peers]); + let arr = []; + [...this.swarm.peers].forEach(peer => arr.push([...peer.topics])); + console.log(arr); process.exit(-1); } }); -- 2.39.3 From aa53cb487b7ed3581585aa454fe7919cc3160f82 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:50:20 +0300 Subject: [PATCH 15/25] I tried to iterate over not iterable object again :sob: --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 75e7b79..335767e 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -23,7 +23,7 @@ class Client extends EventEmitter { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { let arr = []; - [...this.swarm.peers].forEach(peer => arr.push([...peer.topics])); + [...this.swarm.peers].forEach(peer => arr.push([peer.topics])); console.log(arr); process.exit(-1); } -- 2.39.3 From 2ed13e50f796ba68d2ff652e363fc328e10c0622 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:53:36 +0300 Subject: [PATCH 16/25] Ok i will stop exiting to test it properly --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 335767e..566f564 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -24,8 +24,8 @@ class Client extends EventEmitter { if(this.swarm.connections.size > 0) { let arr = []; [...this.swarm.peers].forEach(peer => arr.push([peer.topics])); + console.log([...this.swarm.peers]) console.log(arr); - process.exit(-1); } }); } -- 2.39.3 From 051aa09c2dd8d79b307b4063bee52d804c609220 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:55:23 +0300 Subject: [PATCH 17/25] Opps i had array of arrays of peers in message json --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index a7e629a..571df25 100644 --- a/app.js +++ b/app.js @@ -297,7 +297,7 @@ function sendMessage(e) { onMessageAdded(config.userName, message, config.userAvatar); let peersPublicKeys = []; - peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex'))); + peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).flat(1)); peersPublicKeys.push(swarm.keyPair.publicKey.toString('hex')); const messageObj = JSON.stringify({ -- 2.39.3 From 5d6728f39f75d3da4bb9cbf3623b1e9fe822b59a Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:57:52 +0300 Subject: [PATCH 18/25] Filtering all the peers except myself now --- chatBot/includes/client.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 566f564..46e7d6c 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,10 +22,9 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - let arr = []; - [...this.swarm.peers].forEach(peer => arr.push([peer.topics])); - console.log([...this.swarm.peers]) - console.log(arr); + let peers = [...this.swarm.peers].filter(peer => peer.remotePublicKey.toString('hex').startsWith("51be150")) + console.log(peers[0]) + console.log([peers[0].topics]); } }); } -- 2.39.3 From 5e522981964cf0809d2dd03a37dab92d37f29c45 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:58:37 +0300 Subject: [PATCH 19/25] Ehh its not remotePubKey but just pubKey --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 46e7d6c..dda17f7 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,7 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - let peers = [...this.swarm.peers].filter(peer => peer.remotePublicKey.toString('hex').startsWith("51be150")) + let peers = [...this.swarm.peers].filter(peer => peer.publicKey.toString('hex').startsWith("51be150")) console.log(peers[0]) console.log([peers[0].topics]); } -- 2.39.3 From 7ed5681639bad4b2cf117f8859c9b2e0f818824c Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:59:54 +0300 Subject: [PATCH 20/25] Huh publicKey is undefined lol --- chatBot/includes/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index dda17f7..3ad75cb 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,7 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - let peers = [...this.swarm.peers].filter(peer => peer.publicKey.toString('hex').startsWith("51be150")) + let peers = [...this.swarm.peers].filter(peer => peer && peer.publicKey && peer.publicKey.toString('hex').startsWith("51be150")) console.log(peers[0]) console.log([peers[0].topics]); } -- 2.39.3 From ecfc62ff2c6179b01f71aaa903a3381275eb4cd9 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:00:51 +0300 Subject: [PATCH 21/25] Forgot to check if my temp array is > 0 :sob: --- chatBot/includes/client.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 3ad75cb..ff70f75 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -23,8 +23,12 @@ class Client extends EventEmitter { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { let peers = [...this.swarm.peers].filter(peer => peer && peer.publicKey && peer.publicKey.toString('hex').startsWith("51be150")) - console.log(peers[0]) - console.log([peers[0].topics]); + if(peers.length > 0) { + console.log(peers[0]) + console.log([peers[0].topics]); + } else { + console.log([...peers]); + } } }); } -- 2.39.3 From d993090f8bd217177bce223c3764c3d17ba5806a Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:03:15 +0300 Subject: [PATCH 22/25] I actually didnt fix the issue with array of arrays. Now it should be fine --- app.js | 3 ++- chatBot/includes/client.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 571df25..5a5a527 100644 --- a/app.js +++ b/app.js @@ -297,7 +297,8 @@ function sendMessage(e) { onMessageAdded(config.userName, message, config.userAvatar); let peersPublicKeys = []; - peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex')).flat(1)); + peersPublicKeys.push([...swarm.connections].map(peer => peer.remotePublicKey.toString('hex'))); + peersPublicKeys = peersPublicKeys.flat(1); peersPublicKeys.push(swarm.keyPair.publicKey.toString('hex')); const messageObj = JSON.stringify({ diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index ff70f75..0d23bc5 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,7 +22,7 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - let peers = [...this.swarm.peers].filter(peer => peer && peer.publicKey && peer.publicKey.toString('hex').startsWith("51be150")) + let peers = [...this.swarm.peers].filter(peer => peer && peer.publicKey && peer.publicKey.toString('hex').startsWith("a4eb7f")) if(peers.length > 0) { console.log(peers[0]) console.log([peers[0].topics]); -- 2.39.3 From 4134e20403feb82e9d4648c814e5cbcbb5ca27f8 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:06:00 +0300 Subject: [PATCH 23/25] Array of arrays got fixed but i still cant figure out the issue with topics ehh --- chatBot/includes/client.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 0d23bc5..e1ba9dd 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -22,12 +22,10 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); if(this.swarm.connections.size > 0) { - let peers = [...this.swarm.peers].filter(peer => peer && peer.publicKey && peer.publicKey.toString('hex').startsWith("a4eb7f")) - if(peers.length > 0) { - console.log(peers[0]) - console.log([peers[0].topics]); - } else { - console.log([...peers]); + let peers = [...this.swarm.peers] + for (let peer in peers) { + console.log(peer) + console.log([peer.topics]); } } }); -- 2.39.3 From d233f9e5aa30133a5bdfec9faafc8efede5b25ac Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:07:59 +0300 Subject: [PATCH 24/25] I sometimes really hate nodej --- chatBot/includes/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index e1ba9dd..0aa6253 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -24,8 +24,8 @@ class Client extends EventEmitter { if(this.swarm.connections.size > 0) { let peers = [...this.swarm.peers] for (let peer in peers) { - console.log(peer) - console.log([peer.topics]); + console.log(peers[peer]) + console.log([peers[peer].topics]); } } }); -- 2.39.3 From bfe0bafebca2b11892df1f945df1b69a60c603a4 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:23:47 +0300 Subject: [PATCH 25/25] I removed all of the debugging code for now to push the fix for app.js --- chatBot/includes/client.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 0aa6253..09964f5 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -21,13 +21,6 @@ class Client extends EventEmitter { this.swarm.on('update', () => { console.log(`Peers count: ${this.swarm.connections.size}`); - if(this.swarm.connections.size > 0) { - let peers = [...this.swarm.peers] - for (let peer in peers) { - console.log(peers[peer]) - console.log([peers[peer].topics]); - } - } }); } -- 2.39.3