Fixed sending ON_READY_MESSAGE
This commit is contained in:
parent
d9dbdf4401
commit
8788adbc2b
@ -61,7 +61,7 @@ loadCommands().then(commands => {
|
|||||||
|
|
||||||
bot.on('onBotJoinRoom', () => {
|
bot.on('onBotJoinRoom', () => {
|
||||||
console.log("Bot is ready!");
|
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);
|
bot.joinChatRoom(process.env.LINKUP_ROOM_ID);
|
||||||
|
@ -35,8 +35,15 @@ class Client extends EventEmitter {
|
|||||||
sendMessage(roomPeers, message) {
|
sendMessage(roomPeers, message) {
|
||||||
console.log('Bot name:', this.botName);
|
console.log('Bot name:', this.botName);
|
||||||
const timestamp = Date.now(); // Generate timestamp
|
const timestamp = Date.now(); // Generate timestamp
|
||||||
const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex')));
|
const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex'))); // We remove all the peers that arent included in a room
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
const data = JSON.stringify({name: this.botName, message, timestamp}); // Include timestamp
|
||||||
for (const peer of peers) peer.write(data);
|
for (const peer of peers) peer.write(data);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user