Reworking bot code. Again... #7
@ -1,8 +0,0 @@
|
||||
class ChatRoom {
|
||||
public ChatRoom(topic, peers) {
|
||||
this.topic = topic;
|
||||
this.peers = peers;
|
||||
}
|
||||
}
|
||||
|
||||
export default ChatRoom;
|
@ -46,22 +46,8 @@ class Client extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
sendMessage(roomPeers, message) {
|
||||
console.log('Bot name:', this.botName);
|
||||
const timestamp = Date.now();
|
||||
const messageObj = {
|
||||
type: 'message',
|
||||
name: this.botName,
|
||||
message,
|
||||
timestamp,
|
||||
topic: this.currentTopic // Include the current topic
|
||||
};
|
||||
const data = JSON.stringify(messageObj);
|
||||
const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex')));
|
||||
for (const peer of peers) peer.write(data);
|
||||
}
|
||||
|
||||
sendMessageToAll(message) {
|
||||
// TODO: Make topic here actually work.
|
||||
sendMessage(topic, message) {
|
||||
console.log('Bot name:', this.botName);
|
||||
const timestamp = Date.now();
|
||||
const messageObj = {
|
||||
|
@ -1,10 +0,0 @@
|
||||
class UserPeer {
|
||||
public UserPeer(peer, topics, username, avatar) {
|
||||
this.peer = peer;
|
||||
this.topics = topics;
|
||||
this.username = username;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
}
|
||||
|
||||
export default UserPeer;
|
Loading…
Reference in New Issue
Block a user