Started work on toke logic
This commit is contained in:
parent
5fe1620c20
commit
d85f906a69
7 changed files with 160 additions and 16 deletions
|
|
@ -25,7 +25,7 @@ const {userModel} = require('../userSchema');
|
|||
const permissionModel = require('../permissionSchema');
|
||||
const channelPermissionSchema = require('./channelPermissionSchema');
|
||||
const channelBanSchema = require('./channelBanSchema');
|
||||
const { exceptionHandler } = require('../../utils/loggerUtils');
|
||||
const { exceptionHandler, errorHandler } = require('../../utils/loggerUtils');
|
||||
|
||||
const channelSchema = new mongoose.Schema({
|
||||
id: {
|
||||
|
|
@ -538,7 +538,7 @@ channelSchema.methods.nuke = async function(confirm){
|
|||
}
|
||||
|
||||
//Annoyingly there isnt a good way to do this from 'this'
|
||||
var oldChan = await module.exports.deleteOne({_id: this._id});
|
||||
var oldChan = await this.deleteOne();
|
||||
|
||||
if(oldChan.deletedCount == 0){
|
||||
throw new Error("Server Error: Unable to delete channel! Please report this error to your server administrator, and with timestamp.");
|
||||
|
|
|
|||
|
|
@ -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({});
|
||||
|
|
|
|||
|
|
@ -297,8 +297,8 @@ userSchema.methods.nuke = async function(pass){
|
|||
|
||||
if(this.checkPass(pass)){
|
||||
//Annoyingly there isnt a good way to do this from 'this'
|
||||
var oldUser = await module.exports.userModel.deleteOne(this);
|
||||
|
||||
var oldUser = await this.deleteOne();
|
||||
|
||||
if(oldUser){
|
||||
await this.killAllSessions("If you're seeing this, your account has been deleted. So long, and thanks for all the fish! <3");
|
||||
}else{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue