Started work on toke logic
This commit is contained in:
parent
5fe1620c20
commit
d85f906a69
7 changed files with 160 additions and 16 deletions
|
|
@ -19,6 +19,7 @@ const {mongoose} = require('mongoose');
|
|||
|
||||
//Local Imports
|
||||
const defaultTokes = require("../../../defaultTokes.json");
|
||||
const server = require('../../server');
|
||||
|
||||
const tokeCommandSchema = new mongoose.Schema({
|
||||
command:{
|
||||
|
|
@ -27,6 +28,33 @@ const tokeCommandSchema = new mongoose.Schema({
|
|||
}
|
||||
});
|
||||
|
||||
tokeCommandSchema.pre('save', async function (next){
|
||||
|
||||
//if the command was changed
|
||||
if(this.isModified("command")){
|
||||
//Get server tokebot object
|
||||
const tokebot = server.channelManager.chatHandler.commandPreprocessor.tokebot;
|
||||
|
||||
//Pop the command on to the end
|
||||
tokebot.tokeCommands.push(this.command);
|
||||
}
|
||||
|
||||
|
||||
//All is good, continue on saving.
|
||||
next();
|
||||
});
|
||||
|
||||
tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
||||
//Get server tokebot object
|
||||
const tokebot = server.channelManager.chatHandler.commandPreprocessor.tokebot;
|
||||
|
||||
//Get the index of the command within tokeCommand and splice it out
|
||||
tokebot.tokeCommands.splice(tokebot.tokeCommands.indexOf(this.command),1);
|
||||
|
||||
//All is good, continue on deleting.
|
||||
next();
|
||||
});
|
||||
|
||||
tokeCommandSchema.statics.getCommandStrings = async function(){
|
||||
//Get all toke commands in the DB
|
||||
const tokeDB = await this.find({});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue