diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-31 22:38:06 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-31 22:38:06 -0400 |
commit | c40a94697d64962edda41345e03fa76f51aa431c (patch) | |
tree | 1e258d51d6b19b9918f1d478b3f4c51dca3adc93 /src/lib/models/Level.ts | |
parent | 901d9dfc8c5d95b8c76519e700c624294d4df787 (diff) | |
download | tanzanite-c40a94697d64962edda41345e03fa76f51aa431c.tar.gz tanzanite-c40a94697d64962edda41345e03fa76f51aa431c.tar.bz2 tanzanite-c40a94697d64962edda41345e03fa76f51aa431c.zip |
upgrade typescript, improve workflow, bunch of bug fixes and some other things
Diffstat (limited to 'src/lib/models/Level.ts')
-rw-r--r-- | src/lib/models/Level.ts | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts index 7f418fd..6499bff 100644 --- a/src/lib/models/Level.ts +++ b/src/lib/models/Level.ts @@ -1,5 +1,5 @@ -import { Snowflake } from 'discord.js'; -import { DataTypes, Sequelize } from 'sequelize'; +import { type Snowflake } from 'discord.js'; +import { DataTypes, type Sequelize } from 'sequelize'; import { BaseModel } from './BaseModel'; export interface LevelModel { @@ -14,20 +14,25 @@ export interface LevelModelCreationAttributes { xp?: number; } -// declaration merging so that the fields don't override Sequelize's getters -export interface Level { - /** The user's id. */ - user: Snowflake; +export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> implements LevelModel { + /** + * The user's id. + */ + public declare user: Snowflake; - /** The guild where the user is gaining xp. */ - guild: Snowflake; + /** + * The guild where the user is gaining xp. + */ + public declare guild: Snowflake; - /**The user's xp.*/ - xp: number; -} + /** + * The user's xp. + */ + public declare xp: number; -export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> implements LevelModel { - /** The user's level. */ + /** + * The user's level. + */ public get level(): number { return Level.convertXpToLevel(this.xp); } @@ -44,19 +49,11 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> i } public static convertXpToLevel(xp: number): number { - let i = 1; - let lvl: number; - // eslint-disable-next-line no-constant-condition - while (true) { - const neededXp = Level.convertLevelToXp(i); - if (neededXp > xp) { - lvl = i; - break; - } else { - i++; - } + let i = 0; + while (Level.convertLevelToXp(i + 1) < xp) { + i++; } - return lvl - 1; // I have to do this don't question it ok + return i; } public static convertLevelToXp(level: number): number { |