Added toke counter to statistics schema
This commit is contained in:
parent
80f0c5435f
commit
dc01b8a15a
|
|
@ -17,6 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
//Local Imports
|
||||
const tokeCommandModel = require('../../schemas/tokebot/tokeCommandSchema');
|
||||
const {userModel} = require('../../schemas/userSchema');
|
||||
const statModel = require('../../schemas/statSchema');
|
||||
const statSchema = require('../../schemas/statSchema');
|
||||
|
||||
|
||||
module.exports = class tokebot{
|
||||
|
|
@ -117,6 +119,8 @@ module.exports = class tokebot{
|
|||
|
||||
//Asynchronously tattoo the toke into the users documents within the database so that tokebot doesn't have to wait or worry about DB transactions
|
||||
userModel.tattooToke(this.tokers);
|
||||
//Do the same for the global stat schema
|
||||
statSchema.tattooToke(this.tokers);
|
||||
|
||||
//Set the toke cooldown
|
||||
this.cooldownCounter = this.cooldownTime;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,19 @@ const statSchema = new mongoose.Schema({
|
|||
type: mongoose.SchemaTypes.Number,
|
||||
required: true,
|
||||
default: 0
|
||||
},
|
||||
tokes: [{
|
||||
toke: {
|
||||
type: mongoose.SchemaTypes.Map,
|
||||
required: true,
|
||||
default: new Map()
|
||||
},
|
||||
date: {
|
||||
type: mongoose.SchemaTypes.Date,
|
||||
required: true,
|
||||
default: new Date()
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
//statics
|
||||
|
|
@ -101,4 +113,15 @@ statSchema.statics.incrementChannelCount = async function(){
|
|||
return oldCount;
|
||||
}
|
||||
|
||||
statSchema.statics.tattooToke = async function(toke){
|
||||
//Get the statistics document
|
||||
const stats = await this.getStats();
|
||||
|
||||
//Add the toke to the stat document
|
||||
stats.tokes.push({toke});
|
||||
|
||||
//Save the stat document
|
||||
await stats.save();
|
||||
}
|
||||
|
||||
module.exports = mongoose.model("statistics", statSchema);
|
||||
Loading…
Reference in a new issue