Implemented custom per-channel !toke commands in back-end.
This commit is contained in:
parent
575244ac53
commit
a1fbbea7b7
10 changed files with 159 additions and 29 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ tokeCommandSchema.pre('save', async function (next){
|
|||
});
|
||||
|
||||
tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
||||
//Get server tokebot object
|
||||
//Get server tokebot object (isn't this a fun dot crawler? Why hasn't anyone asked me to stop writing software yet?)
|
||||
const tokebot = server.channelManager.chatHandler.commandPreprocessor.tokebot;
|
||||
|
||||
//Get the index of the command within tokeCommand and splice it out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue