From 116b23d70f6f568accc39c562eb021d529f13ef5 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Thu, 13 Jun 2024 20:47:45 -0400 Subject: [PATCH] Move back to global peer count --- app.js | 2 +- chatBot/bot.js | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index f771de0..d90279f 100644 --- a/app.js +++ b/app.js @@ -759,4 +759,4 @@ function addMessageToStore(topic, messageObj) { // Call this function when loading the rooms initially renderRoomList(); -initialize(); +initialize(); \ No newline at end of file diff --git a/chatBot/bot.js b/chatBot/bot.js index 3e4b961..3ef3d0e 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -5,7 +5,6 @@ import 'dotenv/config'; // Create a new instance of the chatBot class with a valid botName const botName = process.env.BOT_NAME; // Replace 'MyBot' with the desired bot name -const linkupRoomId = process.env.LINKUP_ROOM_ID; // Use the environment variable for room ID // Load commands from the 'commands' directory const commandsDir = path.join(new URL('./commands/', import.meta.url).pathname); @@ -42,31 +41,29 @@ loadCommands().then(commands => { bot.on('onMessage', (peer, message) => { console.log(message); - console.log(`Message received from ${message.peerName}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); + console.log(`Message received from ${message.name}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`); - // Handle all messages as potential AI commands - const userMessage = message.message; + // Check if the message starts with a command prefix + if (message.message.startsWith('!')) { + // Extract the command and arguments + const [command, ...args] = message.message.slice(1).split(' '); - // Find the corresponding command handler (assuming the AI command handler is in 'commands/ai.js') - const commandHandler = commands['ai']; + // Find the corresponding command handler + const commandHandler = commands[command.toLowerCase()]; - // If the command exists, execute its handler - if (commandHandler && typeof commandHandler.handler === 'function') { - commandHandler.handler(bot, [userMessage], message); + // If the command exists, execute its handler + if (commandHandler && typeof commandHandler.handler === 'function') { + commandHandler.handler(bot, args, message); + } } }); bot.on('onBotJoinRoom', () => { console.log("Bot is ready!"); - // Include topic in the message sent when the bot joins the room - bot.sendTextMessage({ - text: process.env.ON_READY_MESSAGE, - topic: linkupRoomId - }); + bot.sendTextMessage(process.env.ON_READY_MESSAGE); }); - // Ensure the bot joins the chat room with the topic information - bot.joinChatRoom(linkupRoomId); + bot.joinChatRoom(process.env.LINKUP_ROOM_ID); }).catch(error => { console.error('Error loading commands:', error); -}); +}); \ No newline at end of file