From b9db313effca7bc7e638df2edf083da920185b3d Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Tue, 11 Jun 2024 17:40:02 -0400 Subject: [PATCH] Fix chatBot --- chatBot/includes/Client.js | 6 +++++- chatBot/includes/FileMessage.js | 6 +++--- chatBot/includes/TextMessage.js | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/chatBot/includes/Client.js b/chatBot/includes/Client.js index 6c76306..45f3ec7 100644 --- a/chatBot/includes/Client.js +++ b/chatBot/includes/Client.js @@ -7,7 +7,7 @@ import FileMessage from "./FileMessage.js"; class Client extends EventEmitter { constructor(botName) { super(); - if(!botName) return console.error("Bot Name is not defined!"); + if (!botName) return console.error("Bot Name is not defined!"); this.botName = botName; this.swarm = new Hyperswarm(); this.joinedRooms = new Set(); // Track the rooms the bot has joined @@ -48,6 +48,10 @@ class Client extends EventEmitter { } joinChatRoom(chatRoomID) { + if (!chatRoomID || typeof chatRoomID !== 'string') { + return console.error("Invalid chat room ID!"); + } + this.joinedRooms.add(chatRoomID); // Add the room to the list of joined rooms this.currentTopic = chatRoomID; // Store the current topic this.discovery = this.swarm.join(Buffer.from(chatRoomID, 'hex'), { client: true, server: true }); diff --git a/chatBot/includes/FileMessage.js b/chatBot/includes/FileMessage.js index b4a78f4..aa055fe 100644 --- a/chatBot/includes/FileMessage.js +++ b/chatBot/includes/FileMessage.js @@ -1,5 +1,5 @@ class FileMessage { - public FileMessage(peerName, fileName, fileUrl, fileType, peerAvatar, topic, timestamp) { + constructor(peerName, fileName, fileUrl, fileType, peerAvatar, topic, timestamp) { this.peerName = peerName; this.fileName = fileName; this.fileUrl = fileUrl; @@ -9,7 +9,7 @@ class FileMessage { this.timestamp = timestamp; } - public toJsonString() { + toJsonString() { return JSON.stringify({ type: 'file', name: this.peerName, @@ -23,4 +23,4 @@ class FileMessage { } } -export default FileMessage; \ No newline at end of file +export default FileMessage; diff --git a/chatBot/includes/TextMessage.js b/chatBot/includes/TextMessage.js index b691113..fa07783 100644 --- a/chatBot/includes/TextMessage.js +++ b/chatBot/includes/TextMessage.js @@ -1,5 +1,5 @@ class TextMessage { - public TextMessage(peerName, peerAvatar, topic, message, timestamp) { + constructor(peerName, peerAvatar, topic, message, timestamp) { this.peerName = peerName; this.peerAvatar = peerAvatar; this.topic = topic; @@ -7,7 +7,7 @@ class TextMessage { this.timestamp = timestamp; } - public toJsonString() { + toJsonString() { return JSON.stringify({ type: 'message', name: this.peerName, @@ -18,9 +18,9 @@ class TextMessage { }); } - public static new(bot, message) { + static new(bot, message) { return new TextMessage(bot.botName, "", bot.currentTopic, message, Date.now()); } } -export default TextMessage; \ No newline at end of file +export default TextMessage;