I actually dont know if it works or not. Changes: Replaced TopicBuffer with chatRoomID and now topicBuffer is being created directly in Client class; Replaced chatBot with Client; Client now extends EventEmitter; bot.on('onMessage', (pear, message) => {}) is now a thing instead of directly putting method in chatBot constructor
This commit is contained in:
@ -1,14 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import chatBot from './includes/chatBot.js'; // Adjust the import path as necessary
|
||||
import 'dotenv/config'
|
||||
|
||||
// Generate a Buffer from the hexadecimal topic value
|
||||
const topicHex = process.env.LINKUP_ROOM_ID;
|
||||
const topicBuffer = Buffer.from(topicHex, 'hex');
|
||||
import Client from './includes/client.js'; // Adjust the import path as necessary
|
||||
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 botName = process.env.BOT_NAME; // Replace 'MyBot' with the desired bot name
|
||||
|
||||
// Load commands from the 'commands' directory
|
||||
const commandsDir = path.join(new URL('./commands/', import.meta.url).pathname);
|
||||
@ -38,7 +34,11 @@ async function loadCommands() {
|
||||
}
|
||||
|
||||
loadCommands().then(commands => {
|
||||
const onMessageReceived = (peer, message) => {
|
||||
// Create the chatBot instance with the defined onMessageReceived function
|
||||
const bot = new Client(process.env.LINKUP_ROOM_ID, botName);
|
||||
|
||||
// We use Event Emitter here to handle new messages
|
||||
bot.on('onMessage', (peer, message) => {
|
||||
if (message.type == "icon") return;
|
||||
console.log(message);
|
||||
|
||||
@ -57,10 +57,7 @@ loadCommands().then(commands => {
|
||||
commandHandler.handler(bot, args, message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create the chatBot instance with the defined onMessageReceived function
|
||||
const bot = new chatBot(topicBuffer, botName, onMessageReceived);
|
||||
})
|
||||
bot.joinChatRoom();
|
||||
|
||||
// Wait for 2 seconds for the bot to connect
|
||||
|
Reference in New Issue
Block a user