From 164efc5b7294ab2f7a1bd8fb088ef6e84faba41f Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sat, 8 Jun 2024 23:31:24 +0300 Subject: [PATCH] Removed Enum class because it does not work :sob: --- chatBot/bot.js | 4 ++-- chatBot/includes/client.js | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index 2122221..e23e5f1 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -38,7 +38,7 @@ loadCommands().then(commands => { const bot = new Client(process.env.LINKUP_ROOM_ID, botName); // We use Event Emitter here to handle new messages - bot.on(Event.onMessage, (peer, message) => { + bot.on('onMessage', (peer, message) => { if (message.type == "icon") return; console.log(message); @@ -59,7 +59,7 @@ loadCommands().then(commands => { } }); - bot.on(Event.onBotJoinRoom, () => { + bot.on('onBotJoinRoom', () => { console.log("Bot is ready!"); }); diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 52770ed..e20c13a 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -12,9 +12,9 @@ class Client extends EventEmitter { setupSwarm() { this.swarm.on('connection', (peer) => { - peer.on('data', message => this.emit(Event.onMessage, peer, JSON.parse(message.toString()))); + peer.on('data', message => this.emit('onMessage', peer, JSON.parse(message.toString()))); peer.on('error', e => { - this.emit(Event.onError, e); + this.emit('onError', e); console.error(`Connection error: ${e}`) }); }); @@ -25,9 +25,9 @@ class Client extends EventEmitter { } joinChatRoom() { - this.discovery = this.swarm.join(this.topicBuffer, { client: true, server: true }); + this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true}); this.discovery.flushed().then(() => { - this.emit(Event.onBotJoinRoom) + this.emit('onBotJoinRoom') console.log(`Bot ${this.botName} joined the chat room.`); }); } @@ -36,7 +36,7 @@ class Client extends EventEmitter { 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); } @@ -46,10 +46,4 @@ class Client extends EventEmitter { } } -enum Event { - onMessage, - onError, - onBotJoinRoom -} - -export default { Client, Event }; +export default Client;