Merge pull request #417 from uukelele-scratch/main

Added ability to sending messages and commands from Mindserver
This commit is contained in:
Max Robinson 2025-02-05 15:47:11 -06:00 committed by GitHub
commit 32d0462c5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 2 deletions

View file

@ -138,6 +138,8 @@ export class Agent {
console.error('Error handling message:', error);
}
}
this.respondFunc = respondFunc
this.bot.on('whisper', respondFunc);
if (settings.profiles.length === 1)

View file

@ -42,6 +42,14 @@ class AgentServerProxy {
console.log(`Restarting agent: ${agentName}`);
this.agent.cleanKill();
});
this.socket.on('send-message', (agentName, message) => {
try {
this.agent.respondFunc("NO USERNAME", message);
} catch (error) {
console.error('Error: ', JSON.stringify(error, Object.getOwnPropertyNames(error)));
}
});
}
login() {

View file

@ -116,6 +116,18 @@ export function createMindServer(port = 8080) {
}, 2000);
});
socket.on('send-message', (agentName, message) => {
if (!inGameAgents[agentName]) {
console.warn(`Agent ${agentName} not logged in, cannot send message via MindServer.`);
return
}
try {
console.log(`Sending message to agent ${agentName}: ${message}`);
inGameAgents[agentName].emit('send-message', agentName, message)
} catch (error) {
console.error('Error: ', error);
}
});
});
server.listen(port, 'localhost', () => {
@ -148,4 +160,4 @@ function stopAllAgents() {
// Optional: export these if you need access to them from other files
export const getIO = () => io;
export const getServer = () => server;
export const getConnectedAgents = () => connectedAgents;
export const getConnectedAgents = () => connectedAgents;

View file

@ -80,6 +80,7 @@
${agent.in_game ? `
<button class="stop-btn" onclick="stopAgent('${agent.name}')">Stop</button>
<button class="restart-btn" onclick="restartAgent('${agent.name}')">Restart</button>
<input type="text" id="messageInput" placeholder="Enter a message or command..."></input><button class="start-btn" onclick="sendMessage('${agent.name}', document.getElementById('messageInput').value)">Send</button>
` : `
<button class="start-btn" onclick="startAgent('${agent.name}')">Start</button>
`}
@ -110,6 +111,10 @@
function shutdown() {
socket.emit('shutdown');
}
function sendMessage(agentName, message) {
socket.emit('send-message', agentName, message)
}
</script>
</body>
</html>
</html>