diff --git a/packages/mrwhale-gamejolt-client/src/client/chat/chat-manager.ts b/packages/mrwhale-gamejolt-client/src/client/chat/chat-manager.ts index a15515c..21ad168 100644 --- a/packages/mrwhale-gamejolt-client/src/client/chat/chat-manager.ts +++ b/packages/mrwhale-gamejolt-client/src/client/chat/chat-manager.ts @@ -65,6 +65,11 @@ export class ChatManager extends events.EventEmitter { return channel.join().receive("ok", (response: { room: Partial }) => { this.roomChannels[roomId] = channel; this.activeRooms[roomId] = new Room(response.room); + channel + .push(Events.MEMBER_WATCH, {}) + .receive("ok", (response: { members: User[] }) => { + this.activeRooms[roomId].members = response.members; + }); }); } diff --git a/packages/mrwhale-gamejolt/src/commands/level/leaderboard.ts b/packages/mrwhale-gamejolt/src/commands/level/leaderboard.ts index 045e7b5..3c124ed 100644 --- a/packages/mrwhale-gamejolt/src/commands/level/leaderboard.ts +++ b/packages/mrwhale-gamejolt/src/commands/level/leaderboard.ts @@ -1,9 +1,9 @@ -import { getLevelFromExp, codeBlock } from "@mrwhale-io/core"; -import { Message, User } from "@mrwhale-io/gamejolt-client"; import * as sequelize from "sequelize"; import * as AsciiTable from "ascii-table"; import { User as GameUser } from "joltite.js"; +import { getLevelFromExp, codeBlock } from "@mrwhale-io/core"; +import { Message, User } from "@mrwhale-io/gamejolt-client"; import { GameJoltCommand } from "../../client/command/gamejolt-command"; import { Score } from "../../database/models/score"; @@ -35,8 +35,8 @@ export default class extends GameJoltCommand { }); } - private createTable(mappedScores: MappedScores[]) { - const table = new AsciiTable("LEADERBOARD"); + private createTable(name: string, mappedScores: MappedScores[]) { + const table = new AsciiTable(name); table.setHeading("#", "Member", "Experience", "Level"); for (let i = 0; i < mappedScores.length; i++) { @@ -60,9 +60,8 @@ export default class extends GameJoltCommand { limit: 10, }); - const room = this.botClient.client.grid.chat.activeRooms[roomId]; + const room = this.botClient.chat.activeRooms[roomId]; const mappedMembers = mapUsers(room.members); - const filteredScores = scores.filter(({ userId }) => Object.keys(mappedMembers).includes(userId.toString()) ); @@ -79,9 +78,9 @@ export default class extends GameJoltCommand { private async getGlobalScores() { const sum: any = sequelize.fn("sum", sequelize.col("exp")); const scores = await Score.findAll({ - attributes: ["userId", sum, "exp"], - order: [["exp", "DESC"]], + attributes: ["userId", [sum, "total"]], group: ["Score.userId"], + order: [[sum, "DESC"]], limit: 10, }); @@ -90,9 +89,9 @@ export default class extends GameJoltCommand { const mappedMembers = mapUsers(members.users); const mappedScores: MappedScores[] = scores.map((score) => ({ - exp: score.exp, + exp: score.getDataValue("total"), user: mappedMembers[score.userId], - level: getLevelFromExp(score.exp), + level: getLevelFromExp(score.getDataValue("total")), })); return mappedScores; @@ -101,8 +100,10 @@ export default class extends GameJoltCommand { async action(message: Message, [command]: [string]): Promise { try { let mappedScores: MappedScores[] = []; + let name = "LEADERBOARD"; if (command && command.toLowerCase().trim() === "global") { mappedScores = await this.getGlobalScores(); + name = "GLOBAL LEADERBOARD"; if (mappedScores.length < 1) { return message.reply("No one is ranked."); @@ -115,7 +116,7 @@ export default class extends GameJoltCommand { } } - const table = this.createTable(mappedScores); + const table = this.createTable(name, mappedScores); return message.reply(codeBlock(table.toString())); } catch {