LinkUp-P2P-Chat/commands.js

27 lines
761 B
JavaScript

// commands.js
import b4a from 'b4a';
import fs from 'fs';
const agentAvatarPath = './assets/agent.png';
let agentAvatar = '';
// Load the agent avatar once when the module is imported
if (fs.existsSync(agentAvatarPath)) {
const avatarBuffer = fs.readFileSync(agentAvatarPath);
agentAvatar = `data:image/png;base64,${b4a.toString(avatarBuffer, 'base64')}`;
}
export default function handleCommand(command, context) {
const { eventEmitter, currentTopic, clearMessages, addMessage } = context;
switch (command.trim().toLowerCase()) {
case '~clear':
clearMessages();
break;
case '~ping':
addMessage('LinkUp', 'pong', agentAvatar, currentTopic());
break;
default:
console.log('Unknown command:', command);
}
}