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