From 824e2dab4280fa5fa655be5866343107ee5cf41c Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 10:51:15 +0300 Subject: [PATCH 1/8] Started working on making the bot be in multiple chatrooms --- chatBot/bot.js | 5 +++-- chatBot/includes/client.js | 11 ++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index 4a3e775..0fef442 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -35,7 +35,7 @@ async function loadCommands() { loadCommands().then(commands => { // Create the chatBot instance with the defined onMessageReceived function - const bot = new Client(process.env.LINKUP_ROOM_ID, botName); + const bot = new Client(botName); // We use Event Emitter here to handle new messages bot.on('onMessage', (peer, message) => { @@ -64,7 +64,8 @@ loadCommands().then(commands => { bot.sendMessage(process.env.ON_READY_MESSAGE); }); - bot.joinChatRoom(); + bot.joinChatRoom(1234); + bot.joinChatRoom(5678); }).catch(error => { console.error('Error loading commands:', error); }); diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index 5033659..6df8ff4 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -2,12 +2,9 @@ import Hyperswarm from 'hyperswarm'; import EventEmitter from 'node:events' class Client extends EventEmitter { - constructor(chatRoomID, botName) { + constructor(botName) { super(); - - if(!chatRoomID || !botName) return console.error("ChatRoomID or BotName is not defined!"); - - this.topicBuffer = Buffer.from(chatRoomID, 'hex'); + if(!botName) return console.error("BotName is not defined!"); this.botName = botName; this.swarm = new Hyperswarm(); this.setupSwarm(); @@ -27,8 +24,8 @@ class Client extends EventEmitter { }); } - joinChatRoom() { - this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true}); + joinChatRoom(chatRoomID) { + this.discovery = this.swarm.join(Buffer.from(chatRoomID, 'hex'), {client: true, server: true}); this.discovery.flushed().then(() => { console.log(`Bot ${this.botName} joined the chat room.`); this.emit('onBotJoinRoom'); -- 2.39.3 From 3df73b97c56d9a01cbc7bfaf3ef6f9c9796883d4 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 10:55:54 +0300 Subject: [PATCH 2/8] Guess gonna try this and then really take a break --- chatBot/bot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index 0fef442..c7edbf1 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -64,8 +64,8 @@ loadCommands().then(commands => { bot.sendMessage(process.env.ON_READY_MESSAGE); }); - bot.joinChatRoom(1234); - bot.joinChatRoom(5678); + bot.joinChatRoom(process.env.LINKUP_ROOM_ID); + bot.joinChatRoom(process.env.LINKUP_ROOM_ID2); }).catch(error => { console.error('Error loading commands:', error); }); -- 2.39.3 From 72bf632cd4efb6c25d2c129198927c87d2af38be Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:07:52 +0300 Subject: [PATCH 3/8] I dont know what to say here because i just need up-to-date repo on my laptop --- app.js | 1 + chatBot/bot.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 950b076..5306609 100644 --- a/app.js +++ b/app.js @@ -438,6 +438,7 @@ function toggleSetupView() { } function writeConfigToFile(filePath) { + console.debug(config) fs.writeFile(filePath, JSON.stringify(config), (err) => { if (err) return console.error(err); console.log("File has been created"); diff --git a/chatBot/bot.js b/chatBot/bot.js index c7edbf1..6417cf4 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} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); + console.log(`Message received from ${message.name}@${peer} 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 840b6e20699771049d605a5ad3677e2b5f37c2dd Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:09:58 +0300 Subject: [PATCH 4/8] Fixed removing rooms --- app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 5306609..244be34 100644 --- a/app.js +++ b/app.js @@ -278,14 +278,15 @@ function leaveRoom() { if (roomItem) { roomItem.remove(); } + + config.rooms = config.rooms.filter(e => e !== currentRoom.topic); + writeConfigToFile("./config.json"); + currentRoom.destroy(); currentRoom = null; } document.querySelector('#chat').classList.add('hidden'); document.querySelector('#setup').classList.remove('hidden'); - - config.rooms = config.rooms.filter(e => e !== currentRoom.topic); - writeConfigToFile("./config.json"); } function sendMessage(e) { @@ -438,7 +439,6 @@ function toggleSetupView() { } function writeConfigToFile(filePath) { - console.debug(config) fs.writeFile(filePath, JSON.stringify(config), (err) => { if (err) return console.error(err); console.log("File has been created"); -- 2.39.3 From c59795a407d1d2b67bd856bf22853170e2785302 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:12:40 +0300 Subject: [PATCH 5/8] Well i hope i fixed it now --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index eca8a0a..0bd98c9 100644 --- a/app.js +++ b/app.js @@ -279,7 +279,7 @@ function leaveRoom() { roomItem.remove(); } - config.rooms = config.rooms.filter(e => e !== currentRoom.topic); + config.rooms = config.rooms.filter(e => e !== currentRoom.topic.toString()); writeConfigToFile("./config.json"); currentRoom.destroy(); -- 2.39.3 From 2a2fbed732bc0c5e717fca57efa9e201d03154fb Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:15:05 +0300 Subject: [PATCH 6/8] Well i didnt... --- app.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.js b/app.js index 0bd98c9..475cedc 100644 --- a/app.js +++ b/app.js @@ -279,6 +279,10 @@ function leaveRoom() { roomItem.remove(); } + console.log(config.rooms); + console.log(config.rooms.filter(e => e !== currentRoom.topic.toString())); + console.log(currentRoom.topic); + console.log(currentRoom.topic.toString()); config.rooms = config.rooms.filter(e => e !== currentRoom.topic.toString()); writeConfigToFile("./config.json"); -- 2.39.3 From d44ef48d8967a2c09296261c9e0f9bee70e7a1fa Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:16:22 +0300 Subject: [PATCH 7/8] I guess i know why it doesnt delete the room now --- app.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app.js b/app.js index 475cedc..f45abdf 100644 --- a/app.js +++ b/app.js @@ -279,10 +279,7 @@ function leaveRoom() { roomItem.remove(); } - console.log(config.rooms); - console.log(config.rooms.filter(e => e !== currentRoom.topic.toString())); - console.log(currentRoom.topic); - console.log(currentRoom.topic.toString()); + console.log(topic); config.rooms = config.rooms.filter(e => e !== currentRoom.topic.toString()); writeConfigToFile("./config.json"); -- 2.39.3 From 8bac7def096b100ae2ce87ebe8b115bad17ddaa3 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:17:20 +0300 Subject: [PATCH 8/8] I fr fixed it this time --- app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app.js b/app.js index f45abdf..302e547 100644 --- a/app.js +++ b/app.js @@ -279,8 +279,7 @@ function leaveRoom() { roomItem.remove(); } - console.log(topic); - config.rooms = config.rooms.filter(e => e !== currentRoom.topic.toString()); + config.rooms = config.rooms.filter(e => e !== topic); writeConfigToFile("./config.json"); currentRoom.destroy(); -- 2.39.3