add votekiss

votekiss
easrng 2022-02-18 14:48:36 -05:00
parent 048af96a19
commit 92860f1ae6
2 changed files with 50 additions and 2 deletions

View File

@ -184,6 +184,16 @@ const setupChatboxEvents = (socket) => {
); );
handled = true; handled = true;
break; 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": case "/help":
const helpMessageContent = document.createElement("span"); const helpMessageContent = document.createElement("span");
helpMessageContent.innerHTML = helpMessageContent.innerHTML =
@ -191,7 +201,8 @@ const setupChatboxEvents = (socket) => {
"&emsp;<code>/help</code> - display this help message<br>" + "&emsp;<code>/help</code> - display this help message<br>" +
"&emsp;<code>/ping [message]</code> - ping all viewers<br>" + "&emsp;<code>/ping [message]</code> - ping all viewers<br>" +
"&emsp;<code>/sync</code> - resyncs you with other viewers<br>" + "&emsp;<code>/sync</code> - resyncs you with other viewers<br>" +
"&emsp;<code>/shrug</code> - appends ¯\\_(ツ)_/¯ to your message"; "&emsp;<code>/shrug</code> - appends ¯\\_(ツ)_/¯ to your message" +
"&emsp;<code>/votekiss</code> - like votekick but gay";
printChatMessage( printChatMessage(
"command-message", "command-message",
@ -327,6 +338,32 @@ const formatTime = (ms) => {
}:${seconds < 10 ? "0" + seconds : seconds}`; }:${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) => { export const logEventToChat = async (event) => {
if (checkDebounce(event)) { if (checkDebounce(event)) {
return; return;
@ -349,12 +386,15 @@ export const logEventToChat = async (event) => {
event.colour, event.colour,
document.createTextNode("left") document.createTextNode("left")
); );
for(let kissed in kisses) delete kisses[kissed][user]
break; break;
} }
case "ChatMessage": { case "ChatMessage": {
const messageContent = document.createElement("span"); const messageContent = document.createElement("span");
messageContent.classList.add("message-content"); messageContent.classList.add("message-content");
if (handleClientCommand(event.data, event.user)) break;
messageContent.append(...(await emojify(event.data))); messageContent.append(...(await emojify(event.data)));
printChatMessage( printChatMessage(
"chat-message", "chat-message",
event.user, event.user,
@ -433,7 +473,10 @@ const beep = () => {
oscillator.stop(context.currentTime + 0.22); oscillator.stop(context.currentTime + 0.22);
}; };
let viewers = [];
export const updateViewerList = (viewers) => { export const updateViewerList = (viewers) => {
viewers = _viewers;
const listContainer = document.querySelector("#viewer-list"); const listContainer = document.querySelector("#viewer-list");
// empty out the current list // empty out the current list

View File

@ -188,10 +188,15 @@ button.small-button {
.chat-message.user-join, .chat-message.user-join,
.chat-message.user-leave, .chat-message.user-leave,
.chat-message.ping { .chat-message.ping,
.chat-message.user-kissed {
font-style: italic; font-style: italic;
} }
.chat-message.user-kissed {
color: #ff6094;
}
.chat-message.set-time, .chat-message.set-time,
.chat-message.set-playing { .chat-message.set-playing {
font-style: italic; font-style: italic;