From ffd2094f161dc4a18023a990c0dbbcd095cb671d Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Fri, 13 Dec 2024 22:07:00 -0500 Subject: [PATCH] Finished up with toke logic. --- src/app/channel/chatHandler.js | 12 +++++++++ src/app/channel/tokebot.js | 38 ++++++++++++++++++++--------- www/css/channel.css | 12 ++++++++- www/css/theme/movie-night.css | 1 - www/js/channel/chatPostprocessor.js | 11 +++++++++ 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index 80df1e7..e7f0211 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -88,6 +88,10 @@ module.exports = class{ this.server.io.in(chan).emit("chatMessage", {user, flair, highLevel, msg, type}); } + relayServerWisper(socket, user, flair, highLevel, msg, type){ + socket.emit("chatMessage", {user, flair, highLevel, msg, type}); + } + relayGlobalChat(user, flair, highLevel, msg, type = 'chat'){ this.server.io.emit("chatMessage", {user, flair, highLevel, msg, type}); } @@ -96,6 +100,14 @@ module.exports = class{ this.relayGlobalChat("Tokebot", "", 10, msg, "toke"); } + relayTokeWhisper(socket, msg){ + this.relayServerWisper(socket, "Tokebot", "", 10, msg, "tokewhisper"); + } + + relayGlobalTokeWhisper(msg){ + this.relayGlobalChat("Tokebot", "", 10, msg, "tokewhisper"); + } + relayServerAnnouncement(msg){ //This codebase is always at a 10 this.relayGlobalChat("Server", "", 10, msg, "announcement"); diff --git a/src/app/channel/tokebot.js b/src/app/channel/tokebot.js index 4578402..fc47814 100644 --- a/src/app/channel/tokebot.js +++ b/src/app/channel/tokebot.js @@ -34,6 +34,7 @@ module.exports = class tokebot{ //Create counter variable this.tokeCounter = 0; + this.cooldownCounter = 0; //Create tokers list this.tokers = []; @@ -77,12 +78,12 @@ module.exports = class tokebot{ //Add the toking user to this.tokers.push(commandObj.socket.user.user); }else{ - console.log('already in toke'); + this.chatHandler.relayTokeWhisper(commandObj.socket, "You're already taking part in this toke!"); } }else{ //if the cooldownTimer exists (we're cooling down the toke) - console.log('cooldown toke'); + this.chatHandler.relayTokeWhisper(commandObj.socket, `Please wait ${this.cooldownCounter} seconds before starting a new group toke.`); } //Toke command found, don't send as chat @@ -94,22 +95,25 @@ module.exports = class tokebot{ } countdown(){ - //if we have more time to go - if(this.tokeCounter > 3){ - console.log(`toke in: ${this.tokeCounter}`); - }else if(this.tokeCounter > 0){ + //If we're in the last three seconds + if(this.tokeCounter <= 3 && this.tokeCounter > 0){ //Callout the last three seconds this.chatHandler.relayTokeCallout(`${this.tokeCounter}...`); - }else{ - //If we have more than one toker + //if the toke is over + }else if(this.tokeCounter < 0){ + //if we only had one toker if(this.tokers.length > 1){ + //call out the solo toke this.chatHandler.relayTokeCallout(`Take a toke ${this.tokers.join(', ')}! ${this.tokers.length} tokers!`); + //if we had multiple tokers }else{ + //call out the toke this.chatHandler.relayTokeCallout(`Take a toke ${this.tokers[0]}.`); } - //Set the cooldown timer - this.cooldownTimer = setTimeout(this.endCooldown.bind(this), 1000 * this.cooldownTime); + //Set the toke cooldown + this.cooldownCounter = this.cooldownTime; + this.cooldownTimer = setTimeout(this.cooldown.bind(this), 1000); //Empty out the tokers array this.tokers = []; @@ -127,8 +131,18 @@ module.exports = class tokebot{ this.tokeTimer = setTimeout(this.countdown.bind(this), 1000) } - endCooldown(){ - this.cooldownTimer = null; + cooldown(){ + //If the cooldown timer isn't over + if(this.cooldownCounter > 0){ + //Decrement toke time + this.cooldownCounter--; + //try again in another second + this.cooldownTimer = setTimeout(this.cooldown.bind(this), 1000); + //If the cooldown is over + }else{ + //Null out the cooldown timer + this.cooldownTimer = null; + } } } diff --git a/www/css/channel.css b/www/css/channel.css index 2831555..0190938 100644 --- a/www/css/channel.css +++ b/www/css/channel.css @@ -151,6 +151,7 @@ p.panel-head-element{ .chat-entry{ display: flex; align-content: center; + font-size: 10pt; } .chat-entry-username{ @@ -196,7 +197,7 @@ span.user-entry{ } .whisper{ - font-size: 0.7em; + font-size: 7pt; } .announcement{ @@ -259,4 +260,13 @@ span.user-entry{ height: 2em; padding: 0; margin: 0.5em; +} + +.toke{ + text-align: center; + font-size: 9pt; +} + +.tokewhisper{ + font-size: 9pt; } \ No newline at end of file diff --git a/www/css/theme/movie-night.css b/www/css/theme/movie-night.css index 3e2794d..9279b3d 100644 --- a/www/css/theme/movie-night.css +++ b/www/css/theme/movie-night.css @@ -228,7 +228,6 @@ p.channel-guide-entry-item{ .chat-entry{ background-color: var(--bg2); border-bottom: 1px solid var(--bg2-alt1); - font-size: 0.8em; } .userlist-color0{/*green0*/ diff --git a/www/js/channel/chatPostprocessor.js b/www/js/channel/chatPostprocessor.js index e905f59..336d6db 100644 --- a/www/js/channel/chatPostprocessor.js +++ b/www/js/channel/chatPostprocessor.js @@ -80,6 +80,7 @@ class chatPostprocessor{ handleChatType(){ if(this.rawData.type == "whisper"){ + //add whisper class this.chatBody.classList.add('whisper'); }else if(this.rawData.type == "announcement"){ //Squash the high-level @@ -88,11 +89,21 @@ class chatPostprocessor{ //Get the username and make it into an announcement title (little hacky but this *IS* postprocessing) const userNode = this.chatEntry.querySelector('.chat-entry-username'); userNode.innerHTML = `${userNode.innerHTML.slice(0,-2)} Announcement`; + //Add/remove relevant classes userNode.classList.remove('chat-entry-username'); userNode.classList.add('announcement-title'); this.chatBody.classList.add('announcement-body'); this.chatEntry.classList.add('announcement'); + }else if(this.rawData.type == "toke" || this.rawData.type == "tokewhisper"){ + //Squash the high-level + this.chatEntry.querySelector('.high-level').remove(); + + //remove the username + this.chatEntry.querySelector('.chat-entry-username').remove(); + + //Add toke/tokewhisper class + this.chatEntry.classList.add(this.rawData.type); } } } \ No newline at end of file