Added !kick command. Updated perm check logic on chan ban to match.
This commit is contained in:
parent
ac8d789edb
commit
2ea3c72a61
4 changed files with 157 additions and 7 deletions
|
|
@ -189,4 +189,80 @@ class commandProcessor{
|
|||
//throw send flag
|
||||
return true;
|
||||
}
|
||||
|
||||
async kick(preprocessor){
|
||||
//Get the current channel from the database
|
||||
const chanDB = await channelModel.findOne({name: preprocessor.socket.chan});
|
||||
|
||||
//Check if the user has permission, and publicly shame them if they don't (lmao)
|
||||
if(await chanDB.permCheck(preprocessor.socket.user, 'kickUser')){
|
||||
//Get username from argument array
|
||||
const username = preprocessor.argumentArray[1];
|
||||
|
||||
//Get channel
|
||||
const channel = this.server.activeChannels.get(preprocessor.socket.chan);
|
||||
|
||||
//get initiator and target user objects
|
||||
const initiator = channel.userList.get(preprocessor.socket.user.user);
|
||||
const target = channel.userList.get(username);
|
||||
|
||||
//get initiator and target override abilities
|
||||
const override = await permissionModel.overrideCheck(preprocessor.socket.user, 'kickUser');
|
||||
const targetOverride = await permissionModel.overrideCheck(target, 'kickUser');
|
||||
|
||||
//If there is no user
|
||||
if(target == null){
|
||||
//silently drop the command
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//If the user is capable of overriding this permission based on site permissions
|
||||
if(override || targetOverride){
|
||||
//If the site rank is equal
|
||||
if(permissionModel.rankToNum(initiator.rank) == permissionModel.rankToNum(target.rank)){
|
||||
//compare chan rank
|
||||
if(permissionModel.rankToNum(initiator.chanRank) <= permissionModel.rankToNum(target.chanRank)){
|
||||
//shame the person running it
|
||||
return true;
|
||||
}
|
||||
//otherwise
|
||||
}else{
|
||||
//compare site rank
|
||||
if(permissionModel.rankToNum(initiator.rank) <= permissionModel.rankToNum(target.rank)){
|
||||
//shame the person running it
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//If the target has a higher chan rank than the initiator
|
||||
if(permissionModel.rankToNum(initiator.chanRank) <= permissionModel.rankToNum(target.chanRank)){
|
||||
//shame the person running it
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Splice out kick
|
||||
preprocessor.commandArray.splice(0,4)
|
||||
|
||||
//Get collect reason
|
||||
var reason = preprocessor.commandArray.join('');
|
||||
|
||||
//If no reason was given
|
||||
if(reason == ''){
|
||||
//Fill in a generic reason
|
||||
reason = "You have been kicked from the channel!";
|
||||
}
|
||||
|
||||
//Kick the user
|
||||
target.disconnect(reason);
|
||||
|
||||
//throw send flag
|
||||
return false;
|
||||
}
|
||||
|
||||
//throw send flag
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue