forked from snxraven/LinkUp-P2P-Chat
Fix chatBot
This commit is contained in:
parent
9a14c10bac
commit
b9db313eff
@ -7,7 +7,7 @@ import FileMessage from "./FileMessage.js";
|
||||
class Client extends EventEmitter {
|
||||
constructor(botName) {
|
||||
super();
|
||||
if(!botName) return console.error("Bot Name is not defined!");
|
||||
if (!botName) return console.error("Bot Name is not defined!");
|
||||
this.botName = botName;
|
||||
this.swarm = new Hyperswarm();
|
||||
this.joinedRooms = new Set(); // Track the rooms the bot has joined
|
||||
@ -48,6 +48,10 @@ class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
joinChatRoom(chatRoomID) {
|
||||
if (!chatRoomID || typeof chatRoomID !== 'string') {
|
||||
return console.error("Invalid chat room ID!");
|
||||
}
|
||||
|
||||
this.joinedRooms.add(chatRoomID); // Add the room to the list of joined rooms
|
||||
this.currentTopic = chatRoomID; // Store the current topic
|
||||
this.discovery = this.swarm.join(Buffer.from(chatRoomID, 'hex'), { client: true, server: true });
|
||||
|
@ -1,5 +1,5 @@
|
||||
class FileMessage {
|
||||
public FileMessage(peerName, fileName, fileUrl, fileType, peerAvatar, topic, timestamp) {
|
||||
constructor(peerName, fileName, fileUrl, fileType, peerAvatar, topic, timestamp) {
|
||||
this.peerName = peerName;
|
||||
this.fileName = fileName;
|
||||
this.fileUrl = fileUrl;
|
||||
@ -9,7 +9,7 @@ class FileMessage {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public toJsonString() {
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
type: 'file',
|
||||
name: this.peerName,
|
||||
|
@ -1,5 +1,5 @@
|
||||
class TextMessage {
|
||||
public TextMessage(peerName, peerAvatar, topic, message, timestamp) {
|
||||
constructor(peerName, peerAvatar, topic, message, timestamp) {
|
||||
this.peerName = peerName;
|
||||
this.peerAvatar = peerAvatar;
|
||||
this.topic = topic;
|
||||
@ -7,7 +7,7 @@ class TextMessage {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public toJsonString() {
|
||||
toJsonString() {
|
||||
return JSON.stringify({
|
||||
type: 'message',
|
||||
name: this.peerName,
|
||||
@ -18,7 +18,7 @@ class TextMessage {
|
||||
});
|
||||
}
|
||||
|
||||
public static new(bot, message) {
|
||||
static new(bot, message) {
|
||||
return new TextMessage(bot.botName, "", bot.currentTopic, message, Date.now());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user