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", "main": "plugin.js",
"name": "gamedig", "name": "gamedig",
"description": "Game server status string", "description": "Game server status string",
"version": "1.1.1", "version": "1.1.3",
"tags": ["commands", "games"], "tags": ["commands", "games"],
"dependencies": ["simplecommands"], "dependencies": ["simplecommands"],
"npmDependencies": ["gamedig@^2.0.23"] "npmDependencies": ["gamedig@^2.0.23"]

View File

@ -33,41 +33,13 @@ interface ICommonResponse {
version: string; 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 { class Parsers {
public static parseMinecraftStatus(response: QueryResult): ICommonResponse | null { public static parseMinecraftStatus(response: QueryResult): ICommonResponse | null {
const result: ICommonResponse = { const result: ICommonResponse = {
name: 'Minecraft', name: 'Minecraft',
connect: response.connect, connect: response.connect.endsWith(':25565')
? response.connect.split(':')[0]
: response.connect,
description: '', description: '',
players: [], players: [],
maxPlayers: 0, maxPlayers: 0,
@ -80,8 +52,7 @@ class Parsers {
return null; return null;
} }
const desc = traverseFindString(raw.vanilla.raw.description) || ''; result.description = response.name.replace(/[^\x00-\x7F]./g, '').replace(/\n/g, ' ');
result.description = desc.replace(/§./g, '').replace(/\n/g, ' ');
result.maxPlayers = response.maxplayers; result.maxPlayers = response.maxplayers;
result.version = raw.vanilla.raw.version.name; result.version = raw.vanilla.raw.version.name;
@ -106,7 +77,7 @@ class GamePlugin extends Plugin {
for (const i in this.config.get('games', [])) { for (const i in this.config.get('games', [])) {
const game = this.config.get('games', [])[i]; const game = this.config.get('games', [])[i];
if (game.game === 'minecraft' && game.host) { if (game.game === 'minecraft' && game.host) {
const port = game.port || 25565; const port = game.port;
const command: any = { const command: any = {
plugin: this.name, plugin: this.name,
name: 'minecraft', name: 'minecraft',
@ -134,11 +105,9 @@ class GamePlugin extends Plugin {
throw new Error(); throw new Error();
} }
} catch (e) { } catch (e) {
console.log(e)
msg.resolve([['field', 'Server is offline.', { type: 'title' }]]); msg.resolve([['field', 'Server is offline.', { type: 'title' }]]);
return true; return true;
} }
if (inclPlayers) { if (inclPlayers) {
keys.push(['field', parsed.players.length ? keys.push(['field', parsed.players.length ?
parsed.players.join(', ') : 'No players', { label: 'Players online' }]); parsed.players.join(', ') : 'No players', { label: 'Players online' }]);

View File

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