this motd is frustrating
This commit is contained in:
parent
1f46817721
commit
3f852ea6fb
@ -2,7 +2,7 @@
|
||||
"main": "plugin.js",
|
||||
"name": "gamedig",
|
||||
"description": "Game server status string",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"tags": ["commands", "games"],
|
||||
"dependencies": ["simplecommands"],
|
||||
"npmDependencies": ["gamedig@^2.0.23"]
|
||||
|
@ -12,13 +12,7 @@ import { query, QueryResult } from 'gamedig';
|
||||
interface IMinecraftType {
|
||||
vanilla: {
|
||||
raw: {
|
||||
description: {
|
||||
extra: [
|
||||
{
|
||||
text: string;
|
||||
}
|
||||
];
|
||||
},
|
||||
description: any,
|
||||
players: {
|
||||
max: number,
|
||||
online: number;
|
||||
@ -39,6 +33,36 @@ 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 = {
|
||||
@ -56,8 +80,8 @@ class Parsers {
|
||||
return null;
|
||||
}
|
||||
|
||||
result.description = raw.vanilla.raw.description.extra[0].text
|
||||
.replace(/§./g, '').replace(/\n/g, ' ');
|
||||
const desc = traverseFindString(raw.vanilla.raw.description) || '';
|
||||
result.description = desc.replace(/§./g, '').replace(/\n/g, ' ');
|
||||
|
||||
result.maxPlayers = response.maxplayers;
|
||||
result.version = raw.vanilla.raw.version.name;
|
||||
@ -110,6 +134,7 @@ class GamePlugin extends Plugin {
|
||||
throw new Error();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
msg.resolve([['field', 'Server is offline.', { type: 'title' }]]);
|
||||
return true;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
},
|
||||
{
|
||||
"name": "gamedig",
|
||||
"version": "1.1.0"
|
||||
"version": "1.1.1"
|
||||
},
|
||||
{
|
||||
"name": "jukebox",
|
||||
|
Loading…
Reference in New Issue
Block a user