From 7e105f8a1e23d3b74c0b5b55d9974b15c51a4b23 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:15:12 +1000 Subject: [PATCH] Fix `/mp status` and `fetchPlayerData` function --- src/commands/mp.ts | 6 +++--- src/models/MPServer.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/mp.ts b/src/commands/mp.ts index 47cf47e..b5c0fca 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -93,10 +93,10 @@ export default class MP { if (!DSS) return console.log('Endpoint failed - status'); DSS.server ? await interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).addFields( - {name: 'Name', value: DSS.server?.name?.length < 1 ? '*`Offline`*' : `\`${DSS?.server?.name}\``}, + {name: 'Name', value: `\`${DSS.server?.name.length > 0 ? DSS.server.name : 'Offline'}\``}, {name: 'Players', value: `${DSS?.slots.used}/${DSS?.slots.capacity}`}, - {name: 'Map', value: DSS?.server.mapName ?? 'Unavailable'} - ).setFooter({text: `Version: ${DSS?.server?.version} | Time: ${`${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}`})]}) : null + {name: 'Map', value: DSS.server?.mapName.length > 0 ? DSS.server.mapName : 'No map'} + ).setFooter({text: `Version: ${DSS?.server?.version.length > 0 ? DSS?.server?.version : '0.0.0.0'} | Time: ${`${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}`})]}) : null }, pallets: async()=>{ const DSS = await fetchData(client, interaction, choiceSelector) as FSData; diff --git a/src/models/MPServer.ts b/src/models/MPServer.ts index dc92918..1b1ce8a 100644 --- a/src/models/MPServer.ts +++ b/src/models/MPServer.ts @@ -57,6 +57,7 @@ export class MPServerSvc { } async fetchPlayerData(serverName:string) { const server = await this.model.findOne({where: {serverName}}); + if (!server) return []; return server.dataValues.playerData ??= []; } async addServer(serverName:string, ip:string, code:string) {