Finished up with toke logic.

This commit is contained in:
rainbow napkin 2024-12-13 22:07:00 -05:00
parent d85f906a69
commit ffd2094f16
5 changed files with 60 additions and 14 deletions

View file

@ -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");

View file

@ -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(){
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;
}
}
}

View file

@ -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{
@ -260,3 +261,12 @@ span.user-entry{
padding: 0;
margin: 0.5em;
}
.toke{
text-align: center;
font-size: 9pt;
}
.tokewhisper{
font-size: 9pt;
}

View file

@ -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*/

View file

@ -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);
}
}
}