JSDoc for rc/schemas/tokebot & src/schemas/user complete.
This commit is contained in:
parent
7b8c44158f
commit
1d5c1037ab
5 changed files with 242 additions and 7 deletions
|
|
@ -21,6 +21,9 @@ const {mongoose} = require('mongoose');
|
|||
const defaultTokes = require("../../../defaultTokes.json");
|
||||
const server = require('../../server');
|
||||
|
||||
/**
|
||||
* Mongoose Schema representing a toke command
|
||||
*/
|
||||
const tokeCommandSchema = new mongoose.Schema({
|
||||
command:{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
|
|
@ -28,8 +31,10 @@ const tokeCommandSchema = new mongoose.Schema({
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Pre-Save middleware, ensures tokebot receives all new toke commands
|
||||
*/
|
||||
tokeCommandSchema.pre('save', async function (next){
|
||||
|
||||
//if the command was changed
|
||||
if(this.isModified("command")){
|
||||
//Get server tokebot object
|
||||
|
|
@ -44,6 +49,9 @@ tokeCommandSchema.pre('save', async function (next){
|
|||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
* Pre-Delete middleware, ensures tokebot removes all old toke commands
|
||||
*/
|
||||
tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
||||
//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;
|
||||
|
|
@ -55,6 +63,10 @@ tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
|||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
* Pulls command strings from DB and reports back
|
||||
* @returns {Array} Array of toke commands pulled from the DB
|
||||
*/
|
||||
tokeCommandSchema.statics.getCommandStrings = async function(){
|
||||
//Get all toke commands in the DB
|
||||
const tokeDB = await this.find({});
|
||||
|
|
@ -71,6 +83,9 @@ tokeCommandSchema.statics.getCommandStrings = async function(){
|
|||
return tokeArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads default tokes into the DB from flat file upon launch
|
||||
*/
|
||||
tokeCommandSchema.statics.loadDefaults = async function(){
|
||||
//Make sure registerToke function is happy
|
||||
const _this = this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue