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] 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); }