Added !kick command. Updated perm check logic on chan ban to match.

This commit is contained in:
rainbow napkin 2024-12-29 03:45:06 -05:00
parent ac8d789edb
commit 2ea3c72a61
4 changed files with 157 additions and 7 deletions

View file

@ -120,7 +120,7 @@ channelSchema.pre('save', async function (next){
if(chanDB != null){
//If we're removing one
if(chanDB.rankList.length > this.rankList.length){
//Child/Parent is *WAY* to atomic family for my tastes :P
//Child/Parent is *WAY* tooo atomic family for my tastes :P
var top = chanDB;
var bottom = this;
}else{
@ -133,18 +133,26 @@ channelSchema.pre('save', async function (next){
await top.populate('rankList.user');
//For each rank in the dommy-top copy of the rank list
top.rankList.forEach((topObj) => {
//Create empty variable for the matched rank
var matchedRank = null;
//For each rank in the old copy of the rank list
//For each rank in the subby-bottom copy of the rank list
bottom.rankList.forEach((bottomObj) => {
//So long as both users exist (we're not working with deleted users)
if(topObj.user != null && bottomObj.user != null){
//If it's the same user
if(topObj.user._id.toString() == bottomObj.user._id.toString()){
//matched rank found
matchedRank = bottomObj;
}
}
});
//If matched rank is null or isn't the topObject rank
if(matchedRank == null || matchedRank.rank != topObj.rank){
//Set top object to found rank
foundRank = topObj;
}

View file

@ -161,6 +161,43 @@ permissionSchema.statics.permCheckByUserDoc = async function(user, perm){
}
}
permissionSchema.statics.overrideCheck = async function(user, perm){
//Check if the user is null
if(user != null){
//This specific call is why we export the userModel the way we do
//Someone will yell at me for circular dependencies but the fucking interpreter isn't :P
const userDB = await userModel.userModel.findOne({user: user.user});
return await this.overrideCheckByUserDoc(userDB, perm);
}else{
return await this.overrideCheckByUserDoc(null, perm);
}
}
permissionSchema.statics.overrideCheckByUserDoc = async function(user, perm){
//Get permission list
const perms = (await this.getPerms()).channelOverrides;
//Set user to anon rank if no rank was found for the given user
if(user == null || user.rank == null){
user ={
rank: "anon"
};
}
//Check if this permission exists
if(perms[perm] != null){
//if so get required rank as a number
requiredRank = this.rankToNum(perms[perm])
//if so get user rank as a number
userRank = user ? this.rankToNum(user.rank) : 0;
//return whether or not the user is equal to or higher than the required rank for this permission
return (userRank >= requiredRank);
}else{
//if not scream and shout
throw new Error(`Permission check '${perm}' not found!`);
}
}
//Middleware for rank checks
permissionSchema.statics.reqPermCheck = function(perm){
return (req, res, next)=>{