From 92860f1ae6fd0e22672ed1316b5dc6ba204f895d Mon Sep 17 00:00:00 2001 From: easrng Date: Fri, 18 Feb 2022 14:48:36 -0500 Subject: [PATCH] add votekiss --- frontend/lib/chat.mjs | 45 ++++++++++++++++++++++++++++++++++++++++++- frontend/styles.css | 7 ++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index 25de6e0..90fa2aa 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -184,6 +184,16 @@ const setupChatboxEvents = (socket) => { ); handled = true; break; + case "/votekiss": + printChatMessage( + "vote-kiss", + "/votekiss", + "b57fdc", + document.createTextNode("you voted to kiss " + args) + ); + handled = false; + // we also handle this on receive + break; case "/help": const helpMessageContent = document.createElement("span"); helpMessageContent.innerHTML = @@ -191,7 +201,8 @@ const setupChatboxEvents = (socket) => { " /help - display this help message
" + " /ping [message] - ping all viewers
" + " /sync - resyncs you with other viewers
" + - " /shrug - appends ¯\\_(ツ)_/¯ to your message"; + " /shrug - appends ¯\\_(ツ)_/¯ to your message" + + " /votekiss - like votekick but gay"; printChatMessage( "command-message", @@ -327,6 +338,32 @@ const formatTime = (ms) => { }:${seconds < 10 ? "0" + seconds : seconds}`; }; +let kisses = {}; +function handleClientCommand(content, user) { + let handled = false; + if (content.startsWith("/")) { + const command = content.toLowerCase().match(/^\/\S+/)[0]; + const args = content.slice(command.length).trim(); + switch (command) { + case "/votekiss": + kisses[args] = kisses[args] || {}; + kisses[args][user] = true; + if (Object.keys(kisses[args]).length > 3) { + printChatMessage( + "user-kissed", + args, + "ff6094", + document.createTextNode("was kissed 💋") + ); + kisses[args] = {}; + } + handled = true; + break; + } + } + return handled; +} + export const logEventToChat = async (event) => { if (checkDebounce(event)) { return; @@ -349,12 +386,15 @@ export const logEventToChat = async (event) => { event.colour, document.createTextNode("left") ); + for(let kissed in kisses) delete kisses[kissed][user] break; } case "ChatMessage": { const messageContent = document.createElement("span"); messageContent.classList.add("message-content"); + if (handleClientCommand(event.data, event.user)) break; messageContent.append(...(await emojify(event.data))); + printChatMessage( "chat-message", event.user, @@ -433,7 +473,10 @@ const beep = () => { oscillator.stop(context.currentTime + 0.22); }; +let viewers = []; + export const updateViewerList = (viewers) => { + viewers = _viewers; const listContainer = document.querySelector("#viewer-list"); // empty out the current list diff --git a/frontend/styles.css b/frontend/styles.css index 51230d7..707580e 100644 --- a/frontend/styles.css +++ b/frontend/styles.css @@ -188,10 +188,15 @@ button.small-button { .chat-message.user-join, .chat-message.user-leave, -.chat-message.ping { +.chat-message.ping, +.chat-message.user-kissed { font-style: italic; } +.chat-message.user-kissed { + color: #ff6094; +} + .chat-message.set-time, .chat-message.set-playing { font-style: italic;