better formatting for help
This commit is contained in:
parent
6a74c23f9c
commit
f84a6cff1b
18
app.js
18
app.js
@ -67,6 +67,13 @@ async function joinRoom(topicStr) {
|
|||||||
await joinSwarm(topicBuffer);
|
await joinSwarm(topicBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createRoom(alias) {
|
||||||
|
const topicBuffer = crypto.randomBytes(32);
|
||||||
|
const topic = b4a.toString(topicBuffer, 'hex');
|
||||||
|
addRoomToList(topic, alias);
|
||||||
|
await joinSwarm(topicBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
async function initialize() {
|
async function initialize() {
|
||||||
try {
|
try {
|
||||||
servePort = getRandomPort();
|
servePort = getRandomPort();
|
||||||
@ -381,17 +388,17 @@ async function joinSwarm(topicBuffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRoomToList(topic) {
|
function addRoomToList(topic, alias) {
|
||||||
const roomList = document.querySelector('#room-list');
|
const roomList = document.querySelector('#room-list');
|
||||||
const roomItem = document.createElement('li');
|
const roomItem = document.createElement('li');
|
||||||
roomItem.textContent = truncateHash(topic);
|
roomItem.textContent = alias || truncateHash(topic);
|
||||||
roomItem.dataset.topic = topic;
|
roomItem.dataset.topic = topic;
|
||||||
|
|
||||||
roomItem.addEventListener('dblclick', () => enterEditMode(roomItem));
|
roomItem.addEventListener('dblclick', () => enterEditMode(roomItem));
|
||||||
roomItem.addEventListener('click', () => switchRoom(topic));
|
roomItem.addEventListener('click', () => switchRoom(topic));
|
||||||
roomList.appendChild(roomItem);
|
roomList.appendChild(roomItem);
|
||||||
|
|
||||||
config.rooms.push({ topic, alias: truncateHash(topic) });
|
config.rooms.push({ topic, alias: alias || truncateHash(topic) });
|
||||||
writeConfigToFile("./config.json");
|
writeConfigToFile("./config.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,10 +521,11 @@ async function sendMessage(e) {
|
|||||||
await handleCommand(message, {
|
await handleCommand(message, {
|
||||||
eventEmitter,
|
eventEmitter,
|
||||||
currentTopic,
|
currentTopic,
|
||||||
clearMessagesCMD,
|
clearMessages,
|
||||||
addMessage: (from, message, avatar, topic) => onMessageAdded(from, message, avatar, topic, timestamp),
|
addMessage: (from, message, avatar, topic) => onMessageAdded(from, message, avatar, topic, timestamp),
|
||||||
joinRoom,
|
joinRoom,
|
||||||
leaveRoom
|
leaveRoom,
|
||||||
|
createRoom
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
13
commands.js
13
commands.js
@ -12,7 +12,7 @@ if (fs.existsSync(agentAvatarPath)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function handleCommand(command, context) {
|
export default async function handleCommand(command, context) {
|
||||||
const { eventEmitter, currentTopic, clearMessagesCMD, addMessage, joinRoom, leaveRoom } = context;
|
const { eventEmitter, currentTopic, clearMessages, addMessage, joinRoom, leaveRoom, createRoom } = context;
|
||||||
|
|
||||||
const args = command.trim().split(' ');
|
const args = command.trim().split(' ');
|
||||||
const cmd = args[0].toLowerCase();
|
const cmd = args[0].toLowerCase();
|
||||||
@ -20,13 +20,13 @@ export default async function handleCommand(command, context) {
|
|||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case '~clear':
|
case '~clear':
|
||||||
clearMessagesCMD();
|
clearMessages();
|
||||||
break;
|
break;
|
||||||
case '~ping':
|
case '~ping':
|
||||||
addMessage('LinkUp', 'pong', agentAvatar, currentTopic());
|
addMessage('LinkUp', 'pong', agentAvatar, currentTopic());
|
||||||
break;
|
break;
|
||||||
case '~help':
|
case '~help':
|
||||||
addMessage('LinkUp', 'Available commands: ~clear, ~ping, ~help, ~join [topic], ~leave', agentAvatar, currentTopic());
|
addMessage('LinkUp', 'Available commands:\n- ~clear\n- ~ping\n- ~help\n- ~join [topic]\n- ~leave\n- ~create [alias]', agentAvatar, currentTopic());
|
||||||
break;
|
break;
|
||||||
case '~join':
|
case '~join':
|
||||||
if (restArgs) {
|
if (restArgs) {
|
||||||
@ -38,6 +38,13 @@ export default async function handleCommand(command, context) {
|
|||||||
case '~leave':
|
case '~leave':
|
||||||
leaveRoom(currentTopic());
|
leaveRoom(currentTopic());
|
||||||
break;
|
break;
|
||||||
|
case '~create':
|
||||||
|
if (restArgs) {
|
||||||
|
await createRoom(restArgs);
|
||||||
|
} else {
|
||||||
|
addMessage('LinkUp', 'Usage: ~create [alias]', agentAvatar, currentTopic());
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('Unknown command:', command);
|
console.log('Unknown command:', command);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user