Skip to content

Commit

Permalink
commands(gameserver): changes w.r.t. gamedig v5
Browse files Browse the repository at this point in the history
Signed-off-by: TRACTION <[email protected]>
  • Loading branch information
iamtraction committed May 20, 2024
1 parent 25c7059 commit 7d954e4
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/commands/gameserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
*/
import { ApplicationCommandOptionType, ChatInputCommandInteraction } from "discord.js";
import { Command } from "@bastion/tesseract";
import gamedig from "gamedig";
import { GameDig } from "gamedig";

import { COLORS } from "../utils/constants.js";

interface Player extends gamedig.Player {
time?: number;
raw?: {
frags?: number;
ping?: number;
};
}

class GameServerCommand extends Command {
constructor() {
super({
Expand Down Expand Up @@ -52,8 +44,8 @@ class GameServerCommand extends Command {
const port = interaction.options.getInteger("port");

// fetch data from the game server
const server = await gamedig.query({
type: game as gamedig.Type,
const server = await GameDig.query({
type: game,
host: hostname,
port: port,
});
Expand Down Expand Up @@ -87,12 +79,10 @@ class GameServerCommand extends Command {
server.players
? server.players
.filter(player => player.name)
.sort((a: Player, b: Player) => b.time - a.time)
.sort((a, b) => b.score - a.score)
.sort((a: Player, b: Player) => b.raw?.frags - a.raw?.frags)
.map((player: Player) => ({
.map(player => ({
name: (player.team ? "[" + player.team + "]" : "") + player.name,
value: "```\nSCORE " + (player.score || player.raw?.frags || 0) + ((player.ping || player.raw?.ping) ? "\tPING " + (player.ping || player.raw?.ping) + "ms" : "") + (player.time ? "\t" + (player.time / 60).toFixed(2) + " minutes" : "") + "```",
value: "```\nSCORE " + (player.score || 0) + (player.team ? "\tTEAM " + player.team : "") + (player.ping ? "\tPING " + player.ping + "ms" : "") + "```",
inline: false,
}))
.slice(0, 5)
Expand Down

0 comments on commit 7d954e4

Please sign in to comment.