From 6639cee8ca9b7e9c65e0f159624337ad80bfe53d Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Sun, 27 Apr 2025 09:49:14 -0400 Subject: [PATCH] Added !resettoke command to tokebot --- src/app/channel/chatHandler.js | 19 ++++++++++++------- src/app/channel/commandPreprocessor.js | 21 +++++++++++++++++++-- src/app/channel/tokebot.js | 8 ++++++++ src/schemas/permissionSchema.js | 6 ++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index 3da520a..4248b61 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -124,16 +124,12 @@ module.exports = class{ } } - relayUserChat(socket, msg, type, links){ - const user = this.server.getSocketInfo(socket); - this.relayChat(user.user, user.flair, user.highLevel, msg, type, socket.chan, links) - } - + //Base chat functions relayChat(user, flair, highLevel, msg, type = 'chat', chan, links){ this.server.io.in(chan).emit("chatMessage", {user, flair, highLevel, msg, type, links}); } - relayServerWisper(socket, user, flair, highLevel, msg, type, links){ + relayPrivateChat(socket, user, flair, highLevel, msg, type, links){ socket.emit("chatMessage", {user, flair, highLevel, msg, type, links}); } @@ -141,18 +137,26 @@ module.exports = class{ this.server.io.emit("chatMessage", {user, flair, highLevel, msg, type, links}); } + //User Chat Functions + relayUserChat(socket, msg, type, links){ + const user = this.server.getSocketInfo(socket); + this.relayChat(user.user, user.flair, user.highLevel, msg, type, socket.chan, links) + } + + //Toke Chat Functions relayTokeCallout(msg, links){ this.relayGlobalChat("Tokebot", "", '∞', msg, "toke", links); } relayTokeWhisper(socket, msg, links){ - this.relayServerWisper(socket, "Tokebot", "", '∞', msg, "tokewhisper", links); + this.relayPrivateChat(socket, "Tokebot", "", '∞', msg, "tokewhisper", links); } relayGlobalTokeWhisper(msg, links){ this.relayGlobalChat("Tokebot", "", '∞', msg, "tokewhisper", links); } + //Announcement Functions relayServerAnnouncement(msg, links){ this.relayGlobalChat("Server", "", '∞', msg, "announcement", links); } @@ -166,6 +170,7 @@ module.exports = class{ } } + //Misc Functions clearChat(chan, user){ const activeChan = this.server.activeChannels.get(chan); diff --git a/src/app/channel/commandPreprocessor.js b/src/app/channel/commandPreprocessor.js index b956de6..7396dac 100644 --- a/src/app/channel/commandPreprocessor.js +++ b/src/app/channel/commandPreprocessor.js @@ -213,7 +213,24 @@ class commandProcessor{ //send it this.chatHandler.relayServerAnnouncement(commandObj.message, commandObj.links); - //throw send flag + //disble send flag + return false; + } + + //throw send flag + return true; + } + + async resettoke(commandObj, preprocessor){ + //Check if the user has permission, and publicly shame them if they don't (lmao) + if(await permissionModel.permCheck(commandObj.socket.user, 'resetToke')){ + //Acknowledge command + this.chatHandler.relayTokeWhisper(commandObj.socket, 'Toke cooldown reset.'); + + //Tell tokebot to reset the toke + preprocessor.tokebot.resetToke(); + + //disable send flag return false; } @@ -229,7 +246,7 @@ class commandProcessor{ if(await chanDB.permCheck(commandObj.socket.user, 'clearChat')){ //Send off the command this.chatHandler.clearChat(commandObj.socket.chan, commandObj.argumentArray[1]); - //throw send flag + //disable send flag return false; } diff --git a/src/app/channel/tokebot.js b/src/app/channel/tokebot.js index fe0444f..b04d7fe 100644 --- a/src/app/channel/tokebot.js +++ b/src/app/channel/tokebot.js @@ -176,4 +176,12 @@ module.exports = class tokebot{ } } + resetToke(){ + //Set cooldown to 0 + this.cooldownCounter = 0; + + //Null out the timer + this.cooldownTimer = null; + } + } diff --git a/src/schemas/permissionSchema.js b/src/schemas/permissionSchema.js index d1621f8..0e6070a 100644 --- a/src/schemas/permissionSchema.js +++ b/src/schemas/permissionSchema.js @@ -51,6 +51,12 @@ const permissionSchema = new mongoose.Schema({ default: "admin", required: true }, + resetToke: { + type: mongoose.SchemaTypes.String, + enum: rankEnum, + default: "admin", + required: true + }, editTokeCommands: { type: mongoose.SchemaTypes.String, enum: rankEnum,