From 344cf309d6154a9e83d45be79e59665e1d9dbfae Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Thu, 22 Apr 2021 16:35:45 +0300 Subject: [PATCH] ignore default port --- gamedig/plugin.json | 2 +- gamedig/plugin.ts | 41 +++++------------------------------------ squeebot.repo.json | 2 +- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/gamedig/plugin.json b/gamedig/plugin.json index 342c87f..e9a82da 100644 --- a/gamedig/plugin.json +++ b/gamedig/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "gamedig", "description": "Game server status string", - "version": "1.1.1", + "version": "1.1.3", "tags": ["commands", "games"], "dependencies": ["simplecommands"], "npmDependencies": ["gamedig@^2.0.23"] diff --git a/gamedig/plugin.ts b/gamedig/plugin.ts index d9fc109..16717b8 100644 --- a/gamedig/plugin.ts +++ b/gamedig/plugin.ts @@ -33,41 +33,13 @@ interface ICommonResponse { version: string; } -/** - * Find a string from a random mash of objects.. - * @param obj Object - * @returns found string or undefined - */ -function traverseFindString(obj: any): string | undefined { - if (typeof obj === 'string') { - return obj; - } - - if (Array.isArray(obj)) { - obj = obj.map((v) => traverseFindString(v)); - for (const p of obj) { - if (typeof p === 'string') { - return p; - } - } - return; - } - - for (const k of Object.keys(obj)) { - const find = traverseFindString(obj[k]); - if (find) { - return find; - } - } - - return; -} - class Parsers { public static parseMinecraftStatus(response: QueryResult): ICommonResponse | null { const result: ICommonResponse = { name: 'Minecraft', - connect: response.connect, + connect: response.connect.endsWith(':25565') + ? response.connect.split(':')[0] + : response.connect, description: '', players: [], maxPlayers: 0, @@ -80,8 +52,7 @@ class Parsers { return null; } - const desc = traverseFindString(raw.vanilla.raw.description) || ''; - result.description = desc.replace(/ยง./g, '').replace(/\n/g, ' '); + result.description = response.name.replace(/[^\x00-\x7F]./g, '').replace(/\n/g, ' '); result.maxPlayers = response.maxplayers; result.version = raw.vanilla.raw.version.name; @@ -106,7 +77,7 @@ class GamePlugin extends Plugin { for (const i in this.config.get('games', [])) { const game = this.config.get('games', [])[i]; if (game.game === 'minecraft' && game.host) { - const port = game.port || 25565; + const port = game.port; const command: any = { plugin: this.name, name: 'minecraft', @@ -134,11 +105,9 @@ class GamePlugin extends Plugin { throw new Error(); } } catch (e) { - console.log(e) msg.resolve([['field', 'Server is offline.', { type: 'title' }]]); return true; } - if (inclPlayers) { keys.push(['field', parsed.players.length ? parsed.players.join(', ') : 'No players', { label: 'Players online' }]); diff --git a/squeebot.repo.json b/squeebot.repo.json index 1bf28aa..3e24e0b 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -19,7 +19,7 @@ }, { "name": "gamedig", - "version": "1.1.1" + "version": "1.1.3" }, { "name": "jukebox",