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

@ -70,6 +70,12 @@ const channelPermissionSchema = new mongoose.Schema({
default: "admin",
required: true
},
editTokeCommands: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,
default: "admin",
required: true
},
deleteChannel: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,

View file

@ -147,6 +147,19 @@ channelSchema.pre('save', async function (next){
}
}
//if the toke commands where changed
if(this.isModified("tokeCommands")){
//Get the active Channel object from the application side of the house
const activeChannel = server.channelManager.activeChannels.get(this.name);
//If the channel is active
if(activeChannel != null){
//Reload the toke command list
activeChannel.tokeCommands = this.tokeCommands;
}
}
next();
});
@ -218,8 +231,7 @@ channelSchema.statics.reqPermCheck = function(perm, chanField = "chanName"){
//If we didnt find a channel
if(chanDB == null){
//FUCK
res.status(401);
return res.send({error:`Cannot perm check non-existant channel!.`});
return errorHandler(res, "You cannot check permissions against a non-existant channel!", 'Unauthorized', 401);
}
//Run a perm check against the current user and permission