Compare commits

..

2 Commits

Author SHA1 Message Date
Raven Scott
0dbd441cd5 Merge branch 'main' of git.ssh.surf:snxraven/LinkUp-P2P-Chat 2024-06-13 20:05:21 -04:00
Raven Scott
b50bd0bbab Room Counts done better 2024-06-13 20:02:01 -04:00

View File

@ -5,6 +5,7 @@ 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);
@ -41,29 +42,31 @@ loadCommands().then(commands => {
bot.on('onMessage', (peer, message) => {
console.log(message);
console.log(`Message received from ${message.name}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`);
console.log(`Message received from ${message.peerName}@${message.topic} at ${new Date(message.timestamp).toLocaleTimeString()}: ${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(' ');
// Handle all messages as potential AI commands
const userMessage = message.message;
// Find the corresponding command handler
const commandHandler = commands[command.toLowerCase()];
// Find the corresponding command handler (assuming the AI command handler is in 'commands/ai.js')
const commandHandler = commands['ai'];
// If the command exists, execute its handler
if (commandHandler && typeof commandHandler.handler === 'function') {
commandHandler.handler(bot, args, message);
}
commandHandler.handler(bot, [userMessage], message);
}
});
bot.on('onBotJoinRoom', () => {
console.log("Bot is ready!");
bot.sendTextMessage(process.env.ON_READY_MESSAGE);
// Include topic in the message sent when the bot joins the room
bot.sendTextMessage({
text: process.env.ON_READY_MESSAGE,
topic: linkupRoomId
});
});
bot.joinChatRoom(process.env.LINKUP_ROOM_ID);
// Ensure the bot joins the chat room with the topic information
bot.joinChatRoom(linkupRoomId);
}).catch(error => {
console.error('Error loading commands:', error);
});