aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/moulberry-bush/level.ts46
-rw-r--r--src/lib/extensions/BotClient.ts2
-rw-r--r--src/lib/models/Level.ts25
3 files changed, 67 insertions, 6 deletions
diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts
new file mode 100644
index 0000000..6dda91a
--- /dev/null
+++ b/src/commands/moulberry-bush/level.ts
@@ -0,0 +1,46 @@
+import { Message } from 'discord.js';
+import { User } from 'discord.js';
+import { BotCommand } from '../../lib/extensions/BotCommand';
+import { Level } from '../../lib/models';
+
+export default class LevelCommand extends BotCommand {
+ constructor() {
+ super('level', {
+ aliases: ['level', 'rank'],
+ description: {
+ content: 'Shows the level of a user',
+ usage: 'level [user]',
+ examples: ['level', 'level @Tyman']
+ },
+ args: [
+ {
+ id: 'user',
+ type: 'user',
+ prompt: {
+ start: 'What user would you like to see the level of?',
+ retry:
+ 'Invalid user. What user would you like to see the level of?',
+ optional: true
+ }
+ }
+ ]
+ });
+ }
+
+ async exec(message: Message, { user }: { user?: User }): Promise<void> {
+ const userLevelRow = await Level.findByPk(
+ user ? user.id : message.author.id
+ );
+ if (userLevelRow) {
+ await message.reply(
+ `${user ? `${user.tag}'s` : 'Your'} level is ${userLevelRow.level} (${
+ userLevelRow.xp
+ } XP)`
+ );
+ } else {
+ await message.reply(
+ `${user ? `${user.tag} does` : 'You do'} not have a level yet!`
+ );
+ }
+ }
+}
diff --git a/src/lib/extensions/BotClient.ts b/src/lib/extensions/BotClient.ts
index 7ac0051..e2de812 100644
--- a/src/lib/extensions/BotClient.ts
+++ b/src/lib/extensions/BotClient.ts
@@ -259,7 +259,7 @@ export class BotClient extends AkairoClient {
{ sequelize: this.db }
);
try {
- await this.db.sync({ alter: true }); // Sync all tables to fix everything if updated
+ await this.db.sync(); // Sync all tables to fix everything if updated
} catch {
// Ignore error
}
diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts
index 65ec8e6..34c53e5 100644
--- a/src/lib/models/Level.ts
+++ b/src/lib/models/Level.ts
@@ -17,11 +17,26 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> {
return Level.convertXpToLevel(this.xp);
}
static convertXpToLevel(xp: number): number {
- // WIP
- return 0;
+ 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++;
+ continue;
+ }
+ }
+ return lvl - 1; // I have to do this don't question it ok
}
- static convertLevelToXp(xp: number): number {
- // WIP
- return 0;
+ static convertLevelToXp(level: number): number {
+ let xp = 0;
+ for (let i = 0; i < level; i++) {
+ xp += 100 * i + 75;
+ }
+ return xp;
}
}