Added toke counter to statistics schema

This commit is contained in:
rainbow napkin 2024-12-14 17:21:16 -05:00
parent 80f0c5435f
commit dc01b8a15a
2 changed files with 28 additions and 1 deletions

View file

@ -17,6 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//Local Imports //Local Imports
const tokeCommandModel = require('../../schemas/tokebot/tokeCommandSchema'); const tokeCommandModel = require('../../schemas/tokebot/tokeCommandSchema');
const {userModel} = require('../../schemas/userSchema'); const {userModel} = require('../../schemas/userSchema');
const statModel = require('../../schemas/statSchema');
const statSchema = require('../../schemas/statSchema');
module.exports = class tokebot{ 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 //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); userModel.tattooToke(this.tokers);
//Do the same for the global stat schema
statSchema.tattooToke(this.tokers);
//Set the toke cooldown //Set the toke cooldown
this.cooldownCounter = this.cooldownTime; this.cooldownCounter = this.cooldownTime;

View file

@ -36,7 +36,19 @@ const statSchema = new mongoose.Schema({
type: mongoose.SchemaTypes.Number, type: mongoose.SchemaTypes.Number,
required: true, required: true,
default: 0 default: 0
} },
tokes: [{
toke: {
type: mongoose.SchemaTypes.Map,
required: true,
default: new Map()
},
date: {
type: mongoose.SchemaTypes.Date,
required: true,
default: new Date()
}
}]
}); });
//statics //statics
@ -101,4 +113,15 @@ statSchema.statics.incrementChannelCount = async function(){
return oldCount; 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); module.exports = mongoose.model("statistics", statSchema);