@zhin.js/plugin-game-hub 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/games/[action:string=].js +17 -0
- package/commands//346/210/230/347/273/251.js +21 -0
- package/commands//346/210/230/347/273/251.ts +26 -0
- package/commands//346/216/222/350/241/214/[query:string=].js +39 -0
- package/commands//346/216/222/350/241/214/[query:string=].ts +49 -0
- package/package.json +5 -5
- package/{plugin.ts → plugin.js} +6 -6
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { formatRuntimeGamesHelp, getRuntimeGame } from '@zhin.js/game-kit';
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: 'Game hub — list loaded games',
|
|
6
|
+
async execute({ params }) {
|
|
7
|
+
const action = String(params.action ?? '').trim();
|
|
8
|
+
if (action) {
|
|
9
|
+
const game = getRuntimeGame(action);
|
|
10
|
+
if (game) {
|
|
11
|
+
const start = game.quickStart ? ` ${game.quickStart}` : '';
|
|
12
|
+
return `发送 \`${game.commandPrefix}${start}\` 开始 ${game.title}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return formatRuntimeGamesHelp();
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { channelKey, getUserGameStats, getRuntimeGame, messageFromCommandInput, } from '@zhin.js/game-kit';
|
|
4
|
+
function formatStats(stats) {
|
|
5
|
+
if (!stats.length)
|
|
6
|
+
return '暂无战绩记录,快去 `/游戏` 开一局吧!';
|
|
7
|
+
const lines = stats.map((s) => {
|
|
8
|
+
const g = getRuntimeGame(s.gameId);
|
|
9
|
+
const title = g ? `${g.icon} ${g.title}` : s.gameId;
|
|
10
|
+
return `• ${title}:${s.wins} 胜 ${s.losses} 负${s.draws ? ` ${s.draws} 平` : ''}(${s.games} 局,得分 ${s.totalScore})`;
|
|
11
|
+
});
|
|
12
|
+
return ['📊 **你的战绩**', '', ...lines].join('\n');
|
|
13
|
+
}
|
|
14
|
+
export default defineCommand({
|
|
15
|
+
description: '查看本人在本群的游戏战绩',
|
|
16
|
+
async execute({ input }) {
|
|
17
|
+
const message = messageFromCommandInput(input);
|
|
18
|
+
const stats = await getUserGameStats(message.$sender.id, channelKey(message));
|
|
19
|
+
return formatStats(stats);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineCommand } from '@zhin.js/command';
|
|
2
|
+
import {
|
|
3
|
+
channelKey,
|
|
4
|
+
getUserGameStats,
|
|
5
|
+
getRuntimeGame,
|
|
6
|
+
messageFromCommandInput,
|
|
7
|
+
} from '@zhin.js/game-kit';
|
|
8
|
+
|
|
9
|
+
function formatStats(stats: Awaited<ReturnType<typeof getUserGameStats>>): string {
|
|
10
|
+
if (!stats.length) return '暂无战绩记录,快去 `/游戏` 开一局吧!';
|
|
11
|
+
const lines = stats.map((s) => {
|
|
12
|
+
const g = getRuntimeGame(s.gameId);
|
|
13
|
+
const title = g ? `${g.icon} ${g.title}` : s.gameId;
|
|
14
|
+
return `• ${title}:${s.wins} 胜 ${s.losses} 负${s.draws ? ` ${s.draws} 平` : ''}(${s.games} 局,得分 ${s.totalScore})`;
|
|
15
|
+
});
|
|
16
|
+
return ['📊 **你的战绩**', '', ...lines].join('\n');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default defineCommand({
|
|
20
|
+
description: '查看本人在本群的游戏战绩',
|
|
21
|
+
async execute({ input }) {
|
|
22
|
+
const message = messageFromCommandInput(input);
|
|
23
|
+
const stats = await getUserGameStats(message.$sender.id, channelKey(message));
|
|
24
|
+
return formatStats(stats);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { channelKey, getGameLeaderboard, getRuntimeGame, getRuntimeGames, messageFromCommandInput, } from '@zhin.js/game-kit';
|
|
4
|
+
function formatLeaderboard(gameId, entries) {
|
|
5
|
+
const g = getRuntimeGame(gameId);
|
|
6
|
+
const title = g ? `${g.icon} ${g.title}` : gameId;
|
|
7
|
+
if (!entries.length) {
|
|
8
|
+
return `${title} 在本群暂无排行,发送 \`/游戏\` 开始第一局!`;
|
|
9
|
+
}
|
|
10
|
+
const lines = entries.map((e, i) => `${i + 1}. ${e.userName} — ${e.wins} 胜 / ${e.games} 局(得分 ${e.totalScore})`);
|
|
11
|
+
return [`🏆 **${title} 本群排行**`, '', ...lines].join('\n');
|
|
12
|
+
}
|
|
13
|
+
export default defineCommand({
|
|
14
|
+
description: '查看本群某游戏排行榜',
|
|
15
|
+
async execute({ input, params }) {
|
|
16
|
+
const query = String(params.query ?? '').trim();
|
|
17
|
+
const games = getRuntimeGames();
|
|
18
|
+
if (!games.length)
|
|
19
|
+
return '暂无已注册游戏。';
|
|
20
|
+
const firstGame = games[0];
|
|
21
|
+
if (!firstGame)
|
|
22
|
+
return '暂无已注册游戏。';
|
|
23
|
+
let gameId = firstGame.id;
|
|
24
|
+
if (query) {
|
|
25
|
+
const hit = games.find((g) => g.id === query
|
|
26
|
+
|| g.title.includes(query)
|
|
27
|
+
|| g.commandPrefix.includes(query)
|
|
28
|
+
|| g.aliases?.some((a) => a.includes(query)));
|
|
29
|
+
if (!hit) {
|
|
30
|
+
const names = games.map((g) => g.title).join('、');
|
|
31
|
+
return `未找到游戏「${query}」。可选:${names}`;
|
|
32
|
+
}
|
|
33
|
+
gameId = hit.id;
|
|
34
|
+
}
|
|
35
|
+
const message = messageFromCommandInput(input);
|
|
36
|
+
const board = await getGameLeaderboard(gameId, channelKey(message));
|
|
37
|
+
return formatLeaderboard(gameId, board);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineCommand } from '@zhin.js/command';
|
|
2
|
+
import {
|
|
3
|
+
channelKey,
|
|
4
|
+
getGameLeaderboard,
|
|
5
|
+
getRuntimeGame,
|
|
6
|
+
getRuntimeGames,
|
|
7
|
+
messageFromCommandInput,
|
|
8
|
+
type LeaderboardEntry,
|
|
9
|
+
} from '@zhin.js/game-kit';
|
|
10
|
+
|
|
11
|
+
function formatLeaderboard(gameId: string, entries: LeaderboardEntry[]): string {
|
|
12
|
+
const g = getRuntimeGame(gameId);
|
|
13
|
+
const title = g ? `${g.icon} ${g.title}` : gameId;
|
|
14
|
+
if (!entries.length) {
|
|
15
|
+
return `${title} 在本群暂无排行,发送 \`/游戏\` 开始第一局!`;
|
|
16
|
+
}
|
|
17
|
+
const lines = entries.map((e, i) =>
|
|
18
|
+
`${i + 1}. ${e.userName} — ${e.wins} 胜 / ${e.games} 局(得分 ${e.totalScore})`,
|
|
19
|
+
);
|
|
20
|
+
return [`🏆 **${title} 本群排行**`, '', ...lines].join('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default defineCommand({
|
|
24
|
+
description: '查看本群某游戏排行榜',
|
|
25
|
+
async execute({ input, params }) {
|
|
26
|
+
const query = String(params.query ?? '').trim();
|
|
27
|
+
const games = getRuntimeGames();
|
|
28
|
+
if (!games.length) return '暂无已注册游戏。';
|
|
29
|
+
const firstGame = games[0];
|
|
30
|
+
if (!firstGame) return '暂无已注册游戏。';
|
|
31
|
+
let gameId = firstGame.id;
|
|
32
|
+
if (query) {
|
|
33
|
+
const hit = games.find(
|
|
34
|
+
(g) => g.id === query
|
|
35
|
+
|| g.title.includes(query)
|
|
36
|
+
|| g.commandPrefix.includes(query)
|
|
37
|
+
|| g.aliases?.some((a) => a.includes(query)),
|
|
38
|
+
);
|
|
39
|
+
if (!hit) {
|
|
40
|
+
const names = games.map((g) => g.title).join('、');
|
|
41
|
+
return `未找到游戏「${query}」。可选:${names}`;
|
|
42
|
+
}
|
|
43
|
+
gameId = hit.id;
|
|
44
|
+
}
|
|
45
|
+
const message = messageFromCommandInput(input);
|
|
46
|
+
const board = await getGameLeaderboard(gameId, channelKey(message));
|
|
47
|
+
return formatLeaderboard(gameId, board);
|
|
48
|
+
},
|
|
49
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-game-hub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Zhin.js 游戏大厅 — 列出已加载的游戏插件 (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"./package.json": "./package.json"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
|
-
"plugin.
|
|
17
|
+
"plugin.js",
|
|
18
18
|
"schema.json",
|
|
19
19
|
"commands",
|
|
20
20
|
"src",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zhin.js/command": "1.0.
|
|
27
|
-
"@zhin.js/game-kit": "2.0.
|
|
26
|
+
"@zhin.js/command": "1.0.4",
|
|
27
|
+
"@zhin.js/game-kit": "2.0.3",
|
|
28
28
|
"@zhin.js/plugin-runtime": "1.1.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"zhin": {
|
|
47
47
|
"protocol": 1,
|
|
48
48
|
"type": "plugin",
|
|
49
|
-
"entry": "./plugin.
|
|
49
|
+
"entry": "./plugin.js",
|
|
50
50
|
"engine": "^1.0.0",
|
|
51
51
|
"runtime": "trusted",
|
|
52
52
|
"features": [
|
package/{plugin.ts → plugin.js}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
1
2
|
import { definePlugin } from '@zhin.js/plugin-runtime';
|
|
2
|
-
|
|
3
3
|
/**
|
|
4
4
|
* Plugin Runtime game hub — lists games registered via `registerRuntimeGame`.
|
|
5
5
|
* Interactive hub menus are deferred; `/games` command shows help text.
|
|
6
6
|
*/
|
|
7
7
|
export default definePlugin({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
name: 'game-hub',
|
|
9
|
+
metadata: {
|
|
10
|
+
displayName: 'Game Hub',
|
|
11
|
+
},
|
|
12
|
+
setup() { },
|
|
13
13
|
});
|