Implemented custom per-channel !toke commands in back-end.

This commit is contained in:
rainbow napkin 2024-12-15 09:51:32 -05:00
parent 575244ac53
commit a1fbbea7b7
10 changed files with 159 additions and 29 deletions

View file

@ -20,9 +20,10 @@ const flairModel = require('../../schemas/flairSchema');
const permissionModel = require('../../schemas/permissionSchema');
module.exports = class{
constructor(server, name){
constructor(server, chanDB){
this.server = server;
this.name = name;
this.name = chanDB.name;
this.tokeCommands = chanDB.tokeCommands;
//Keeping these in a map was originally a vestige but it's more preformant than an array or object so :P
this.userList = new Map();
}
@ -37,8 +38,11 @@ module.exports = class{
if(userObj){
//Add this socket on to the userobject
userObj.sockets.push(socket.id);
//If the user is joining the channel
}else{
//Grab flair
await userDB.populate('flair');
//Set user object
userObj = new connectedUser(userDB, chanRank, this, socket);
}

View file

@ -109,7 +109,7 @@ module.exports = class{
if(!activeChan){
//If not, make it so
activeChan = new activeChannel(this, socket.chan);
activeChan = new activeChannel(this, chanDB);
this.activeChannels.set(socket.chan, activeChan);
}

View file

@ -52,10 +52,22 @@ module.exports = class tokebot{
}
tokeProcessor(commandObj){
const foundToke = this.tokeCommands.indexOf(commandObj.argumentArray[0]);
//Check for site-wide toke commands
if(this.tokeCommands.indexOf(commandObj.argumentArray[0]) != -1){
//Seems lame to set a bool in an if statement but this would've made a really ugly turinary
var foundToke = true;
}else{
//Find the users active channel
const activeChan = this.server.activeChannels.get(commandObj.socket.chan);
//Check if they're using a channel-only toke
//This should be safe to do without a null check but someone prove me wrong lmao
var foundToke = (activeChan.tokeCommands.indexOf(commandObj.argumentArray[0]) != -1);
}
//If we found a toke
if(foundToke != -1){
if(foundToke){
//If there is no active toke or cooldown (new toke)
if(this.tokeTimer == null && this.cooldownTimer == null){
//Call-out toke start