this motd is frustrating
This commit is contained in:
parent
1f46817721
commit
3f852ea6fb
@ -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.0",
|
"version": "1.1.1",
|
||||||
"tags": ["commands", "games"],
|
"tags": ["commands", "games"],
|
||||||
"dependencies": ["simplecommands"],
|
"dependencies": ["simplecommands"],
|
||||||
"npmDependencies": ["gamedig@^2.0.23"]
|
"npmDependencies": ["gamedig@^2.0.23"]
|
||||||
|
@ -12,13 +12,7 @@ import { query, QueryResult } from 'gamedig';
|
|||||||
interface IMinecraftType {
|
interface IMinecraftType {
|
||||||
vanilla: {
|
vanilla: {
|
||||||
raw: {
|
raw: {
|
||||||
description: {
|
description: any,
|
||||||
extra: [
|
|
||||||
{
|
|
||||||
text: string;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
},
|
|
||||||
players: {
|
players: {
|
||||||
max: number,
|
max: number,
|
||||||
online: number;
|
online: number;
|
||||||
@ -39,6 +33,36 @@ 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 = {
|
||||||
@ -56,8 +80,8 @@ class Parsers {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.description = raw.vanilla.raw.description.extra[0].text
|
const desc = traverseFindString(raw.vanilla.raw.description) || '';
|
||||||
.replace(/§./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;
|
||||||
@ -110,6 +134,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "gamedig",
|
"name": "gamedig",
|
||||||
"version": "1.1.0"
|
"version": "1.1.1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "jukebox",
|
"name": "jukebox",
|
||||||
|
Loading…
Reference in New Issue
Block a user