ignore default port

This commit is contained in:
Evert Prants 2021-04-22 16:35:45 +03:00
parent 5b8f0a57e7
commit 344cf309d6
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 7 additions and 38 deletions

View File

@ -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"]

View File

@ -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' }]);

View File

@ -19,7 +19,7 @@
},
{
"name": "gamedig",
"version": "1.1.1"
"version": "1.1.3"
},
{
"name": "jukebox",