diff --git a/chatBot/bot.js b/chatBot/bot.js index b2844c3..c1359b9 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -39,7 +39,6 @@ loadCommands().then(commands => { // We use Event Emitter here to handle new messages bot.on('onMessage', (peer, message) => { - if (message.type == "icon") return; console.log(message); console.log(`Message received from ${message.name}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index ae51599..426b094 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -13,7 +13,12 @@ class Client extends EventEmitter { setupSwarm() { this.swarm.on('connection', (peer) => { - peer.on('data', message => this.emit('onMessage', peer, JSON.parse(message.toString()))); + peer.on('data', message => { + if(message.type === "message") this.emit('onMessage', peer, JSON.parse(message.toString())); + if(message.type === "icon") this.emit('onIcon', peer, JSON.parse(message.toString())); + if(message.type === "file") this.emit('onFile', peer, JSON.parse(message.toString())); + }); + peer.on('error', e => { this.emit('onError', e); console.error(`Connection error: ${e}`) @@ -30,8 +35,6 @@ class Client extends EventEmitter { const peerTopics = [peerInfo.topics] .filter(topics => topics) .map(topics => topics.map(topic => b4a.toString(topic, 'hex'))); - - console.log(`Peer ${peer} is in topic(s) [${peerTopics.join(", ")}]`); }); }); }