forked from snxraven/LinkUp-P2P-Chat
Started working on making the bot be in multiple chatrooms
This commit is contained in:
@ -2,12 +2,9 @@ import Hyperswarm from 'hyperswarm';
|
||||
import EventEmitter from 'node:events'
|
||||
|
||||
class Client extends EventEmitter {
|
||||
constructor(chatRoomID, botName) {
|
||||
constructor(botName) {
|
||||
super();
|
||||
|
||||
if(!chatRoomID || !botName) return console.error("ChatRoomID or BotName is not defined!");
|
||||
|
||||
this.topicBuffer = Buffer.from(chatRoomID, 'hex');
|
||||
if(!botName) return console.error("BotName is not defined!");
|
||||
this.botName = botName;
|
||||
this.swarm = new Hyperswarm();
|
||||
this.setupSwarm();
|
||||
@ -27,8 +24,8 @@ class Client extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
joinChatRoom() {
|
||||
this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true});
|
||||
joinChatRoom(chatRoomID) {
|
||||
this.discovery = this.swarm.join(Buffer.from(chatRoomID, 'hex'), {client: true, server: true});
|
||||
this.discovery.flushed().then(() => {
|
||||
console.log(`Bot ${this.botName} joined the chat room.`);
|
||||
this.emit('onBotJoinRoom');
|
||||
|
Reference in New Issue
Block a user