diff --git a/src/app/channel/tokebot.js b/src/app/channel/tokebot.js index 438bf0b..c9a0f3b 100644 --- a/src/app/channel/tokebot.js +++ b/src/app/channel/tokebot.js @@ -17,6 +17,8 @@ along with this program. If not, see .*/ //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; diff --git a/src/schemas/statSchema.js b/src/schemas/statSchema.js index bcc3a4d..db1b316 100644 --- a/src/schemas/statSchema.js +++ b/src/schemas/statSchema.js @@ -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); \ No newline at end of file