@zhin.js/plugin-game-hub 1.1.0 → 1.1.2
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/README.md +1 -1
- package/commands/games/{[[action]].js → [[action]]/index.js} +5 -4
- package/commands/games/{[[action]].ts → [[action]]/index.ts} +5 -4
- package/commands//346/210/230/347/273/{251.js → 251/index.js} +7 -6
- package/commands//346/210/230/347/273/{251.ts → 251/index.ts} +9 -7
- package/commands//346/216/222/350/241/214/{[[query]].js → [[query]]/index.js} +8 -7
- package/commands//346/216/222/350/241/214/{[[query]].ts → [[query]]/index.ts} +9 -9
- package/package.json +9 -5
- package/plugin.js +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { defineCommand } from 'zhin.js/command';
|
|
3
|
-
import {
|
|
3
|
+
import { gameFeatureId } from '@zhin.js/game-kit';
|
|
4
4
|
export default defineCommand({
|
|
5
5
|
description: 'Game hub — list loaded games',
|
|
6
6
|
params: { action: { type: 'string', default: '' } },
|
|
7
|
-
async execute({ params }) {
|
|
7
|
+
async execute({ params, project }) {
|
|
8
|
+
const games = project(gameFeatureId);
|
|
8
9
|
const action = String(params.action ?? '').trim();
|
|
9
10
|
if (action) {
|
|
10
|
-
const game =
|
|
11
|
+
const game = games.get(action);
|
|
11
12
|
if (game) {
|
|
12
13
|
const start = game.quickStart ? ` ${game.quickStart}` : '';
|
|
13
14
|
return `发送 \`${game.commandPrefix}${start}\` 开始 ${game.title}`;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return games.formatHelp();
|
|
17
18
|
},
|
|
18
19
|
});
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { defineCommand } from 'zhin.js/command';
|
|
2
|
-
import {
|
|
2
|
+
import { gameFeatureId, type GameIndex } from '@zhin.js/game-kit';
|
|
3
3
|
|
|
4
4
|
export default defineCommand({
|
|
5
5
|
description: 'Game hub — list loaded games',
|
|
6
6
|
params: { action: { type: 'string', default: '' } },
|
|
7
|
-
async execute({ params }) {
|
|
7
|
+
async execute({ params, project }) {
|
|
8
|
+
const games = project<GameIndex>(gameFeatureId);
|
|
8
9
|
const action = String(params.action ?? '').trim();
|
|
9
10
|
if (action) {
|
|
10
|
-
const game =
|
|
11
|
+
const game = games.get(action);
|
|
11
12
|
if (game) {
|
|
12
13
|
const start = game.quickStart ? ` ${game.quickStart}` : '';
|
|
13
14
|
return `发送 \`${game.commandPrefix}${start}\` 开始 ${game.title}`;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return games.formatHelp();
|
|
17
18
|
},
|
|
18
19
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { defineCommand } from 'zhin.js/command';
|
|
3
|
-
import { channelKey,
|
|
4
|
-
function formatStats(stats) {
|
|
3
|
+
import { channelKey, gameFeatureId, messageFromCommandInput, } from '@zhin.js/game-kit';
|
|
4
|
+
function formatStats(index, stats) {
|
|
5
5
|
if (!stats.length)
|
|
6
6
|
return '暂无战绩记录,快去 `/游戏` 开一局吧!';
|
|
7
7
|
const lines = stats.map((s) => {
|
|
8
|
-
const g =
|
|
8
|
+
const g = index.get(s.gameId);
|
|
9
9
|
const title = g ? `${g.icon} ${g.title}` : s.gameId;
|
|
10
10
|
return `• ${title}:${s.wins} 胜 ${s.losses} 负${s.draws ? ` ${s.draws} 平` : ''}(${s.games} 局,得分 ${s.totalScore})`;
|
|
11
11
|
});
|
|
@@ -13,9 +13,10 @@ function formatStats(stats) {
|
|
|
13
13
|
}
|
|
14
14
|
export default defineCommand({
|
|
15
15
|
description: '查看本人在本群的游戏战绩',
|
|
16
|
-
async execute({ input }) {
|
|
16
|
+
async execute({ input, project }) {
|
|
17
|
+
const index = project(gameFeatureId);
|
|
17
18
|
const message = messageFromCommandInput(input);
|
|
18
|
-
const stats = await
|
|
19
|
-
return formatStats(stats);
|
|
19
|
+
const stats = await index.getUserStats(message.$sender.id, channelKey(message));
|
|
20
|
+
return formatStats(index, stats);
|
|
20
21
|
},
|
|
21
22
|
});
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { defineCommand } from 'zhin.js/command';
|
|
2
2
|
import {
|
|
3
3
|
channelKey,
|
|
4
|
-
|
|
5
|
-
getRuntimeGame,
|
|
4
|
+
gameFeatureId,
|
|
6
5
|
messageFromCommandInput,
|
|
6
|
+
type GameIndex,
|
|
7
|
+
type UserGameStats,
|
|
7
8
|
} from '@zhin.js/game-kit';
|
|
8
9
|
|
|
9
|
-
function formatStats(stats:
|
|
10
|
+
function formatStats(index: GameIndex, stats: UserGameStats[]): string {
|
|
10
11
|
if (!stats.length) return '暂无战绩记录,快去 `/游戏` 开一局吧!';
|
|
11
12
|
const lines = stats.map((s) => {
|
|
12
|
-
const g =
|
|
13
|
+
const g = index.get(s.gameId);
|
|
13
14
|
const title = g ? `${g.icon} ${g.title}` : s.gameId;
|
|
14
15
|
return `• ${title}:${s.wins} 胜 ${s.losses} 负${s.draws ? ` ${s.draws} 平` : ''}(${s.games} 局,得分 ${s.totalScore})`;
|
|
15
16
|
});
|
|
@@ -18,9 +19,10 @@ function formatStats(stats: Awaited<ReturnType<typeof getUserGameStats>>): strin
|
|
|
18
19
|
|
|
19
20
|
export default defineCommand({
|
|
20
21
|
description: '查看本人在本群的游戏战绩',
|
|
21
|
-
async execute({ input }) {
|
|
22
|
+
async execute({ input, project }) {
|
|
23
|
+
const index = project<GameIndex>(gameFeatureId);
|
|
22
24
|
const message = messageFromCommandInput(input);
|
|
23
|
-
const stats = await
|
|
24
|
-
return formatStats(stats);
|
|
25
|
+
const stats = await index.getUserStats(message.$sender.id, channelKey(message));
|
|
26
|
+
return formatStats(index, stats);
|
|
25
27
|
},
|
|
26
28
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { defineCommand } from 'zhin.js/command';
|
|
3
|
-
import { channelKey,
|
|
4
|
-
function formatLeaderboard(gameId, entries) {
|
|
5
|
-
const g =
|
|
3
|
+
import { channelKey, gameFeatureId, messageFromCommandInput, } from '@zhin.js/game-kit';
|
|
4
|
+
function formatLeaderboard(index, gameId, entries) {
|
|
5
|
+
const g = index.get(gameId);
|
|
6
6
|
const title = g ? `${g.icon} ${g.title}` : gameId;
|
|
7
7
|
if (!entries.length) {
|
|
8
8
|
return `${title} 在本群暂无排行,发送 \`/游戏\` 开始第一局!`;
|
|
@@ -13,9 +13,10 @@ function formatLeaderboard(gameId, entries) {
|
|
|
13
13
|
export default defineCommand({
|
|
14
14
|
description: '查看本群某游戏排行榜',
|
|
15
15
|
params: { query: { type: 'string', default: '' } },
|
|
16
|
-
async execute({ input, params }) {
|
|
16
|
+
async execute({ input, params, project }) {
|
|
17
|
+
const index = project(gameFeatureId);
|
|
17
18
|
const query = String(params.query ?? '').trim();
|
|
18
|
-
const games =
|
|
19
|
+
const games = index.list();
|
|
19
20
|
if (!games.length)
|
|
20
21
|
return '暂无已注册游戏。';
|
|
21
22
|
const firstGame = games[0];
|
|
@@ -34,7 +35,7 @@ export default defineCommand({
|
|
|
34
35
|
gameId = hit.id;
|
|
35
36
|
}
|
|
36
37
|
const message = messageFromCommandInput(input);
|
|
37
|
-
const board = await
|
|
38
|
-
return formatLeaderboard(gameId, board);
|
|
38
|
+
const board = await index.getLeaderboard(gameId, channelKey(message));
|
|
39
|
+
return formatLeaderboard(index, gameId, board);
|
|
39
40
|
},
|
|
40
41
|
});
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { defineCommand } from 'zhin.js/command';
|
|
2
2
|
import {
|
|
3
3
|
channelKey,
|
|
4
|
-
|
|
5
|
-
getRuntimeGame,
|
|
6
|
-
getRuntimeGames,
|
|
4
|
+
gameFeatureId,
|
|
7
5
|
messageFromCommandInput,
|
|
8
6
|
type LeaderboardEntry,
|
|
7
|
+
type GameIndex,
|
|
9
8
|
} from '@zhin.js/game-kit';
|
|
10
9
|
|
|
11
|
-
function formatLeaderboard(gameId: string, entries: LeaderboardEntry[]): string {
|
|
12
|
-
const g =
|
|
10
|
+
function formatLeaderboard(index: GameIndex, gameId: string, entries: LeaderboardEntry[]): string {
|
|
11
|
+
const g = index.get(gameId);
|
|
13
12
|
const title = g ? `${g.icon} ${g.title}` : gameId;
|
|
14
13
|
if (!entries.length) {
|
|
15
14
|
return `${title} 在本群暂无排行,发送 \`/游戏\` 开始第一局!`;
|
|
@@ -23,9 +22,10 @@ function formatLeaderboard(gameId: string, entries: LeaderboardEntry[]): string
|
|
|
23
22
|
export default defineCommand({
|
|
24
23
|
description: '查看本群某游戏排行榜',
|
|
25
24
|
params: { query: { type: 'string', default: '' } },
|
|
26
|
-
async execute({ input, params }) {
|
|
25
|
+
async execute({ input, params, project }) {
|
|
26
|
+
const index = project<GameIndex>(gameFeatureId);
|
|
27
27
|
const query = String(params.query ?? '').trim();
|
|
28
|
-
const games =
|
|
28
|
+
const games = index.list();
|
|
29
29
|
if (!games.length) return '暂无已注册游戏。';
|
|
30
30
|
const firstGame = games[0];
|
|
31
31
|
if (!firstGame) return '暂无已注册游戏。';
|
|
@@ -44,7 +44,7 @@ export default defineCommand({
|
|
|
44
44
|
gameId = hit.id;
|
|
45
45
|
}
|
|
46
46
|
const message = messageFromCommandInput(input);
|
|
47
|
-
const board = await
|
|
48
|
-
return formatLeaderboard(gameId, board);
|
|
47
|
+
const board = await index.getLeaderboard(gameId, channelKey(message));
|
|
48
|
+
return formatLeaderboard(index, gameId, board);
|
|
49
49
|
},
|
|
50
50
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-game-hub",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Zhin.js 游戏大厅 — 列出已加载的游戏插件 (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zhin.js/game-kit": "1.1.
|
|
26
|
+
"@zhin.js/game-kit": "1.1.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^6.0.3",
|
|
30
30
|
"vitest": "^4.1.10",
|
|
31
|
-
"zhin.js": "1.1.
|
|
31
|
+
"zhin.js": "1.1.2"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
@@ -52,13 +52,17 @@
|
|
|
52
52
|
{
|
|
53
53
|
"package": "@zhin.js/command",
|
|
54
54
|
"api": "^1.0.0"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"package": "@zhin.js/game-kit",
|
|
58
|
+
"api": "^1.0.0"
|
|
55
59
|
}
|
|
56
60
|
],
|
|
57
61
|
"plugins": []
|
|
58
62
|
},
|
|
59
63
|
"peerDependencies": {
|
|
60
|
-
"@zhin.js/command": "^1.1.
|
|
61
|
-
"zhin.js": "^1.1.
|
|
64
|
+
"@zhin.js/command": "^1.1.1",
|
|
65
|
+
"zhin.js": "^1.1.2"
|
|
62
66
|
},
|
|
63
67
|
"peerDependenciesMeta": {
|
|
64
68
|
"@zhin.js/command": {
|
package/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { definePlugin } from 'zhin.js';
|
|
3
3
|
/**
|
|
4
|
-
* Plugin Runtime game hub —
|
|
4
|
+
* Plugin Runtime game hub — commands read the generation-owned GameIndex projection.
|
|
5
5
|
* Interactive hub menus are deferred; `/games` command shows help text.
|
|
6
6
|
*/
|
|
7
7
|
export default definePlugin({
|