Compare commits
11 Commits
babde932e7
...
1c07819d91
Author | SHA1 | Date | |
---|---|---|---|
1c07819d91 | |||
|
8bac7def09 | ||
|
d44ef48d89 | ||
|
2a2fbed732 | ||
|
c59795a407 | ||
|
33e0a13f93 | ||
|
840b6e2069 | ||
|
72bf632cd4 | ||
|
966873774c | ||
|
3df73b97c5 | ||
|
824e2dab42 |
7
app.js
7
app.js
@ -278,14 +278,15 @@ function leaveRoom() {
|
||||
if (roomItem) {
|
||||
roomItem.remove();
|
||||
}
|
||||
|
||||
config.rooms = config.rooms.filter(e => e !== topic);
|
||||
writeConfigToFile("./config.json");
|
||||
|
||||
currentRoom.destroy();
|
||||
currentRoom = null;
|
||||
}
|
||||
document.querySelector('#chat').classList.add('hidden');
|
||||
document.querySelector('#setup').classList.remove('hidden');
|
||||
|
||||
config.rooms = config.rooms.filter(e => e !== currentRoom.topic);
|
||||
writeConfigToFile("./config.json");
|
||||
}
|
||||
|
||||
function sendMessage(e) {
|
||||
|
@ -35,14 +35,14 @@ async function loadCommands() {
|
||||
|
||||
loadCommands().then(commands => {
|
||||
// Create the chatBot instance with the defined onMessageReceived function
|
||||
const bot = new Client(process.env.LINKUP_ROOM_ID, botName);
|
||||
const bot = new Client(botName);
|
||||
|
||||
// We use Event Emitter here to handle new messages
|
||||
bot.on('onMessage', (peer, message) => {
|
||||
if (message.type == "icon") return;
|
||||
console.log(message);
|
||||
|
||||
console.log(`Message received from ${message.name} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`);
|
||||
console.log(`Message received from ${message.name}@${peer} at ${new Date(message.timestamp).toLocaleTimeString()}: ${message.message}`);
|
||||
|
||||
// Check if the message starts with a command prefix
|
||||
if (message.message.startsWith('!')) {
|
||||
@ -64,7 +64,8 @@ loadCommands().then(commands => {
|
||||
bot.sendMessage(process.env.ON_READY_MESSAGE);
|
||||
});
|
||||
|
||||
bot.joinChatRoom();
|
||||
bot.joinChatRoom(process.env.LINKUP_ROOM_ID);
|
||||
bot.joinChatRoom(process.env.LINKUP_ROOM_ID2);
|
||||
}).catch(error => {
|
||||
console.error('Error loading commands:', error);
|
||||
});
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user