forked from forktown/watch-party
handle chat commands better
in preparation for other commands such as for resyncing
This commit is contained in:
parent
72c212a100
commit
af4b23e879
1 changed files with 35 additions and 17 deletions
|
@ -12,24 +12,42 @@ const setupChatboxEvents = (socket) => {
|
||||||
if (content.trim().length) {
|
if (content.trim().length) {
|
||||||
input.value = "";
|
input.value = "";
|
||||||
|
|
||||||
if (
|
// handle commands
|
||||||
content.toLowerCase() == "/ping" ||
|
if (content.startsWith("/")) {
|
||||||
content.toLowerCase().startsWith("/ping ")
|
const command = content.toLowerCase().match(/^\/\S+/)[0];
|
||||||
) {
|
const args = content.slice(command.length).trim();
|
||||||
socket.send(
|
|
||||||
JSON.stringify({
|
let handled = false;
|
||||||
op: "Ping",
|
switch (command) {
|
||||||
data: content.slice(5).trim(),
|
case "/ping":
|
||||||
})
|
socket.send(
|
||||||
);
|
JSON.stringify({
|
||||||
} else {
|
op: "Ping",
|
||||||
socket.send(
|
data: args,
|
||||||
JSON.stringify({
|
})
|
||||||
op: "ChatMessage",
|
);
|
||||||
data: content,
|
handled = true;
|
||||||
})
|
break;
|
||||||
);
|
case "/help":
|
||||||
|
// TODO: print help in chat
|
||||||
|
handled = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle regular chat messages
|
||||||
|
socket.send(
|
||||||
|
JSON.stringify({
|
||||||
|
op: "ChatMessage",
|
||||||
|
data: content,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue