Stats: Add stats command to show a users data

like cards owned, level progression and date registered
This commit is contained in:
2022-09-12 22:18:53 +02:00
parent 465f1f3221
commit af3f1237c6
2 changed files with 64 additions and 2 deletions

View File

@@ -3,6 +3,8 @@ const {
Model
} = require('sequelize');
const levelModifier = 0.5;
module.exports = (sequelize, DataTypes) => {
class User extends Model {
/**
@@ -21,8 +23,23 @@ module.exports = (sequelize, DataTypes) => {
experience: this.experience + parseInt(amount)
});
}
async getLevel() {
return Math.ceil(0.5 * Math.sqrt(this.experience));
level() {
let currentLevel = Math.ceil(levelModifier * Math.sqrt(this.experience));
let nextLevelExperience = Math.pow((currentLevel + 1) / levelModifier, 2);
let remaining = nextLevelExperience - this.experience;
return {
currentLevel: currentLevel,
currentExperience: this.experience,
nextLevelExperience: nextLevelExperience,
remaining: remaining
};
}
async cards() {
return await sequelize.models.Card.findAndCountAll({
where: {
userId: this.id
}
});
}
//instance methods
async getCardsWithCharactersCounted() {