Compare commits
No commits in common. "cc654112b288df91543f898f47bc31993e7d4c80" and "9461368c021171267043ba9b83f9956766536e69" have entirely different histories.
cc654112b2
...
9461368c02
@ -57,14 +57,14 @@ loadCommands().then(commands => {
|
||||
commandHandler.handler(bot, args, message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('onBotJoinRoom', () => {
|
||||
console.log("Bot is ready!");
|
||||
bot.sendMessage(process.env.ON_READY_MESSAGE);
|
||||
});
|
||||
|
||||
})
|
||||
bot.joinChatRoom();
|
||||
|
||||
// Wait for 2 seconds for the bot to connect
|
||||
setTimeout(() => {
|
||||
// Send a message
|
||||
bot.sendMessage(process.env.ON_READY_MESSAGE);
|
||||
}, 2000); // Adjust the delay as necessary
|
||||
}).catch(error => {
|
||||
console.error('Error loading commands:', error);
|
||||
});
|
||||
|
@ -4,9 +4,6 @@ import EventEmitter from 'node:events'
|
||||
class Client extends EventEmitter {
|
||||
constructor(chatRoomID, botName) {
|
||||
super();
|
||||
|
||||
if(!chatRoomID || !botName) return console.error("ChatRoomID or BotName is not defined!");
|
||||
|
||||
this.topicBuffer = Buffer.from(chatRoomID, 'hex');
|
||||
this.botName = botName;
|
||||
this.swarm = new Hyperswarm();
|
||||
@ -15,11 +12,8 @@ class Client extends EventEmitter {
|
||||
|
||||
setupSwarm() {
|
||||
this.swarm.on('connection', (peer) => {
|
||||
peer.on('data', message => this.emit('onMessage', peer, JSON.parse(message.toString())));
|
||||
peer.on('error', e => {
|
||||
this.emit('onError', e);
|
||||
console.error(`Connection error: ${e}`)
|
||||
});
|
||||
peer.on('data', message => this.emit("onMessage", peer, JSON.parse(message.toString())));
|
||||
peer.on('error', e => console.log(`Connection error: ${e}`));
|
||||
});
|
||||
|
||||
this.swarm.on('update', () => {
|
||||
@ -31,7 +25,6 @@ class Client extends EventEmitter {
|
||||
this.discovery = this.swarm.join(this.topicBuffer, { client: true, server: true });
|
||||
this.discovery.flushed().then(() => {
|
||||
console.log(`Bot ${this.botName} joined the chat room.`);
|
||||
this.emit('onBotJoinRoom');
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user