Commit 27a3cef5 authored by nanahira's avatar nanahira

catchup and possibly locale updates

parent 485f1f7a
......@@ -9,7 +9,7 @@
"version": "1.2.1",
"license": "MIT",
"dependencies": {
"koishi-thirdeye": "^9.1.1",
"koishi-thirdeye": "^9.2.4",
"minecraft-protocol": "^1.30.0",
"source-map-support": "^0.5.21"
},
......@@ -37,7 +37,7 @@
"ws": "^8.5.0"
},
"peerDependencies": {
"koishi": "^4.4.0"
"koishi": "^4.4.1"
}
},
"node_modules/@ampproject/remapping": {
......@@ -1092,9 +1092,9 @@
}
},
"node_modules/@koishijs/core": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==",
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz",
"integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==",
"peer": true,
"dependencies": {
"@koishijs/utils": "^5.2.0",
......@@ -1556,9 +1556,9 @@
"dev": true
},
"node_modules/@types/ws": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz",
"integrity": "sha512-NOn5eIcgWLOo6qW8AcuLZ7G8PycXu0xTxxkS6Q18VWFxgPUSOwV0pBj2a/4viNZVu25i7RIB7GttdkAIUUXOOg==",
"version": "8.5.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz",
"integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==",
"peer": true,
"dependencies": {
"@types/node": "*"
......@@ -5397,17 +5397,17 @@
}
},
"node_modules/koishi": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==",
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz",
"integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==",
"peer": true,
"dependencies": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.0",
"@koishijs/core": "^4.4.1",
"@koishijs/utils": "^5.2.0",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.2.2",
"@types/ws": "^8.5.2",
"axios": "^0.24.0",
"file-type": "^16.5.3",
"koa": "^2.13.4",
......@@ -5415,16 +5415,16 @@
"parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0",
"proxy-agent": "^5.0.0",
"ws": "^8.4.2"
"ws": "^8.5.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/koishi-decorators": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.1.1.tgz",
"integrity": "sha512-AaumjnVTT8N7jJ67w16blSez9z+Pi+duuJusheIq3Hmkvx+iRxkpp3w0IvlU69gHqdQRK3Z4qNNC+KrMPDORUg==",
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.2.5.tgz",
"integrity": "sha512-PYVXFNdSCbifr12L0JSiIZGQsax1cENyxzWg0LTRemgTp5iZgj/QPXqgh4p3IWZ8YIPYQ53vSS6lBG2PnhKOWA==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......@@ -5433,24 +5433,24 @@
"typed-reflector": "^1.0.9"
},
"peerDependencies": {
"koishi": "^4.2.1"
"koishi": "^4.4.1"
}
},
"node_modules/koishi-thirdeye": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.1.tgz",
"integrity": "sha512-Oy5Y36Jq9ZnJJLRKmbEx0yFP7lqazBXMxjBLdfl5+5Oyx1JdiYWlPLVQ8ggbmLTKmDXZ87s3c5nfxAN/4iBA8A==",
"version": "9.2.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.4.tgz",
"integrity": "sha512-maJkIivNEjDZaTDeOa2GSDxUX4pjie0zzjk7VxPnt/RONS9UHGUJ2A6CkcqYdz4CY6OKoWyhX0wzDnJkk/rUOg==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1",
"koishi-decorators": "^1.2.5",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2",
"typed-reflector": "^1.0.9"
},
"peerDependencies": {
"koishi": "^4.4.0",
"koishi": "^4.4.1",
"schemastery": "^3.1.0"
}
},
......@@ -8848,9 +8848,9 @@
}
},
"@koishijs/core": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==",
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz",
"integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==",
"peer": true,
"requires": {
"@koishijs/utils": "^5.2.0",
......@@ -9279,9 +9279,9 @@
"dev": true
},
"@types/ws": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.2.tgz",
"integrity": "sha512-NOn5eIcgWLOo6qW8AcuLZ7G8PycXu0xTxxkS6Q18VWFxgPUSOwV0pBj2a/4viNZVu25i7RIB7GttdkAIUUXOOg==",
"version": "8.5.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz",
"integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==",
"peer": true,
"requires": {
"@types/node": "*"
......@@ -12200,17 +12200,17 @@
}
},
"koishi": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==",
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz",
"integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==",
"peer": true,
"requires": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.0",
"@koishijs/core": "^4.4.1",
"@koishijs/utils": "^5.2.0",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.2.2",
"@types/ws": "^8.5.2",
"axios": "^0.24.0",
"file-type": "^16.5.3",
"koa": "^2.13.4",
......@@ -12218,13 +12218,13 @@
"parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0",
"proxy-agent": "^5.0.0",
"ws": "^8.4.2"
"ws": "^8.5.0"
}
},
"koishi-decorators": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.1.1.tgz",
"integrity": "sha512-AaumjnVTT8N7jJ67w16blSez9z+Pi+duuJusheIq3Hmkvx+iRxkpp3w0IvlU69gHqdQRK3Z4qNNC+KrMPDORUg==",
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.2.5.tgz",
"integrity": "sha512-PYVXFNdSCbifr12L0JSiIZGQsax1cENyxzWg0LTRemgTp5iZgj/QPXqgh4p3IWZ8YIPYQ53vSS6lBG2PnhKOWA==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......@@ -12234,13 +12234,13 @@
}
},
"koishi-thirdeye": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.1.tgz",
"integrity": "sha512-Oy5Y36Jq9ZnJJLRKmbEx0yFP7lqazBXMxjBLdfl5+5Oyx1JdiYWlPLVQ8ggbmLTKmDXZ87s3c5nfxAN/4iBA8A==",
"version": "9.2.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.4.tgz",
"integrity": "sha512-maJkIivNEjDZaTDeOa2GSDxUX4pjie0zzjk7VxPnt/RONS9UHGUJ2A6CkcqYdz4CY6OKoWyhX0wzDnJkk/rUOg==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1",
"koishi-decorators": "^1.2.5",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2",
......
{
"name": "koishi-plugin-mcinfo",
"description": "Koishi 的 Minecraft 服务器信息查询插件。",
"description": "Koishi plugin for Minecraft server MOTD query.",
"version": "1.2.1",
"main": "dist/index.js",
"types": "dist/src/index.d.ts",
......@@ -27,12 +27,12 @@
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-mcinfo",
"dependencies": {
"koishi-thirdeye": "^9.1.1",
"koishi-thirdeye": "^9.2.4",
"minecraft-protocol": "^1.30.0",
"source-map-support": "^0.5.21"
},
"peerDependencies": {
"koishi": "^4.4.0"
"koishi": "^4.4.1"
},
"devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
......
......@@ -7,29 +7,26 @@ import {
CommandExample,
PutOption,
InjectLogger,
CommandDescription,
PutTemplate,
Renderer,
} from 'koishi-thirdeye';
import { ping, NewPingResult } from 'minecraft-protocol';
import { Logger, segment } from 'koishi';
@DefinePlugin({ name: 'mcinfo' })
export default class MinecraftInfoPlugin extends BasePlugin<any> {
private getServerText(result: NewPingResult) {
private getServerPrefix(result: NewPingResult) {
let text = '';
if (result.favicon?.startsWith('data:image/png;base64,')) {
const base64Text = result.favicon.slice(22).replace(/\n/g, '');
text += segment.image(`base64://${base64Text}`);
text += '\n';
}
if (result.version) {
text += `版本: ${result.version.name}\n`;
}
if (result.players) {
text += `玩家: ${result.players.online}/${result.players.max}\n`;
for (const player of result.players.sample || []) {
text += `* ${player.name}\n`;
}
}
text += `延迟: ${result.latency} ms`;
return text;
}
private getServerSuffix(result: NewPingResult) {
let text = '';
if (result.description) {
text += '\n\n';
if (typeof result.description === 'string') {
......@@ -47,15 +44,37 @@ export default class MinecraftInfoPlugin extends BasePlugin<any> {
private logger: Logger;
@UseCommand('mcinfo', '查询 Minecraft 服务器信息。')
@CommandDescription({ en: 'Query Minecraft server info.' })
@CommandUsage('查询指定的 Minecraft 服务器信息。')
@CommandExample('mcinfo -s 2b2t.org')
@CommandExample('mcinfo -s 2b2t.org -p 25565')
async onQueryServer(
@PutOption('host', '-s <host:string> 服务器地址') host: string,
@PutOption('port', '-p <port:posint> 服务器端口,默认 25565') port: number,
@PutOption('host', '-s <host:string> 服务器地址', {
description: { en: 'Server address' },
})
host: string,
@PutOption('port', '-p <port:posint> 服务器端口,默认 25565', {
description: { en: 'Server port' },
})
port: number,
@PutTemplate('plzSpecifyHost', {
zh: '请指定服务器地址。',
en: 'Please specify server host.',
})
plzSpecifyHost: Renderer<void>,
@PutTemplate('connectFail', {
zh: '连接服务器 {hostString} 失败,请检查服务器地址是否正确。',
en: 'Failed to connect to server {hostString}, please check the server address.',
})
connectFail: Renderer<{ hostString: string }>,
@PutTemplate('serverInfo', {
zh: `版本: {version.name}\n玩家: {players.online}/{players.max}\n{samplePlayers}\n延迟: {latency} ms\n`,
en: `Version: {version.name}\nPlayers: {players.online}/{players.max}\n{samplePlayers}\nLatency: {latency} ms\n`,
})
serverInfo: Renderer<NewPingResult & { samplePlayers: string }>,
) {
if (!host) {
return '请指定服务器地址。';
return plzSpecifyHost();
}
if (!port && host.includes(':')) {
const splited = host.split(':');
......@@ -65,12 +84,18 @@ export default class MinecraftInfoPlugin extends BasePlugin<any> {
const hostString = port ? `${host}:${port}` : host;
try {
const result = (await ping({ host, port })) as NewPingResult;
return `${hostString}\n${this.getServerText(result)}`;
return `${hostString}\n${this.getServerPrefix(result)}${serverInfo({
...result,
samplePlayers: (result.players?.sample || [])
.map((player) => `* ${player.name}\n`)
.join('\n'),
})}${this.getServerSuffix(result)}`;
} catch (e) {
this.logger.error(
`Failed to query Minecraft server ${hostString}: ${e.message}`,
);
return `连接服务器 ${hostString} 失败,请检查服务器地址是否正确。`;
return connectFail({ hostString });
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment