@zhin.js/plugin-idiom-chain 1.0.1 → 1.0.3

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.
Files changed (62) hide show
  1. package/commands/chain/[action:string=].ts +15 -0
  2. package/lib/chain-command.d.ts +4 -3
  3. package/lib/chain-command.js +5 -1
  4. package/lib/chain-command.js.map +1 -1
  5. package/lib/engine.d.ts +0 -1
  6. package/lib/game-flow.d.ts +6 -7
  7. package/lib/game-flow.js +26 -21
  8. package/lib/game-flow.js.map +1 -1
  9. package/lib/idiom-provider.d.ts +0 -1
  10. package/lib/idiom-provider.js +1 -1
  11. package/lib/idiom-provider.js.map +1 -1
  12. package/lib/index.d.ts +8 -2
  13. package/lib/index.js +8 -25
  14. package/lib/index.js.map +1 -1
  15. package/lib/memory-db.d.ts +6 -0
  16. package/lib/memory-db.js +18 -0
  17. package/lib/memory-db.js.map +1 -0
  18. package/lib/models.d.ts +5 -4
  19. package/lib/models.js +2 -2
  20. package/lib/models.js.map +1 -1
  21. package/lib/runtime-store.d.ts +6 -0
  22. package/lib/runtime-store.js +7 -0
  23. package/lib/runtime-store.js.map +1 -0
  24. package/lib/session-service.d.ts +1 -3
  25. package/lib/session-service.js +1 -4
  26. package/lib/session-service.js.map +1 -1
  27. package/lib/view.d.ts +1 -2
  28. package/lib/view.js +1 -1
  29. package/lib/view.js.map +1 -1
  30. package/middlewares/chain-alias.ts +18 -0
  31. package/middlewares/chain-text.ts +75 -0
  32. package/package.json +36 -10
  33. package/plugin.ts +64 -0
  34. package/schema.json +6 -0
  35. package/src/chain-command.ts +12 -3
  36. package/src/game-flow.ts +32 -28
  37. package/src/idiom-provider.ts +1 -1
  38. package/src/index.ts +9 -30
  39. package/src/memory-db.ts +22 -0
  40. package/src/models.ts +7 -4
  41. package/src/runtime-store.ts +9 -0
  42. package/src/session-service.ts +2 -5
  43. package/src/view.ts +2 -2
  44. package/lib/chain-command.d.ts.map +0 -1
  45. package/lib/commands.d.ts +0 -6
  46. package/lib/commands.d.ts.map +0 -1
  47. package/lib/commands.js +0 -95
  48. package/lib/commands.js.map +0 -1
  49. package/lib/engine.d.ts.map +0 -1
  50. package/lib/game-flow.d.ts.map +0 -1
  51. package/lib/hub-register.d.ts +0 -5
  52. package/lib/hub-register.d.ts.map +0 -1
  53. package/lib/hub-register.js +0 -31
  54. package/lib/hub-register.js.map +0 -1
  55. package/lib/idiom-provider.d.ts.map +0 -1
  56. package/lib/index.d.ts.map +0 -1
  57. package/lib/models.d.ts.map +0 -1
  58. package/lib/session-service.d.ts.map +0 -1
  59. package/lib/view.d.ts.map +0 -1
  60. package/plugin.yml +0 -2
  61. package/src/commands.ts +0 -116
  62. package/src/hub-register.ts +0 -32
@@ -1 +0,0 @@
1
- {"version":3,"file":"idiom-provider.d.ts","sourceRoot":"","sources":["../src/idiom-provider.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA+BD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMzD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAChB,UAAU,EAAE,CAWd;AAED,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAChB,UAAU,GAAG,IAAI,CAInB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,UAAU,CAI9D;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAChB,MAAM,GAAG,IAAI,CAEf;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAChB,cAAc,CAyBhB;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAOrE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEvE,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,MAAM;QACd,oBAAoB,EAAE;YACpB,EAAE,EAAE,MAAM,CAAC;YACX,OAAO,EAAE,MAAM,CAAC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W,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,QAAA,MAAM,SAAS,IAAI,CAAC;AAMpB,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,UAAU,GAAE,MAAM,EAAO,EACzB,WAAW,CAAC,EAAE,MAAM,GACnB,WAAW,CAkDb;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/plugin.yml DELETED
@@ -1,2 +0,0 @@
1
- name: "@zhin.js/plugin-idiom-chain"
2
- description: "成语接龙"
package/src/commands.ts DELETED
@@ -1,116 +0,0 @@
1
- import { Message, MessageCommand, getActionFromMessage, type Plugin } from 'zhin.js';
2
- import {
3
- buildChoiceFallbackMap,
4
- channelKey,
5
- normalizeChainAction,
6
- parseChoicePayload,
7
- registerGameTextMiddleware,
8
- resolveGameChoice,
9
- resolveGameTextPayload,
10
- } from '@zhin.js/game-shared';
11
- import { CHAIN_PREFIX, handleChoice, processIdiomText } from './game-flow.js';
12
- import { runChainCommand } from './chain-command.js';
13
- import type { SessionService } from './session-service.js';
14
-
15
- const VALID_CHOICES = ['hint', 'skip', 'quit', 'restart'] as const;
16
-
17
- function registerPattern(
18
- plugin: Plugin,
19
- pattern: string,
20
- desc: string,
21
- getServices: () => SessionService | null,
22
- ): void {
23
- plugin.addCommand(
24
- new MessageCommand(pattern)
25
- .desc(desc)
26
- .action(async (message, result) => {
27
- const services = getServices();
28
- if (!services) return '成语接龙需要启用 database 配置。';
29
- const raw = (result.params.action as string | undefined) ?? '';
30
- return runChainCommand(plugin, services, message, normalizeChainAction(raw));
31
- }),
32
- );
33
- }
34
-
35
- export function registerCommands(plugin: Plugin, getServices: () => SessionService | null): void {
36
- registerPattern(plugin, '/chain [action:word]', '成语接龙(chain)', getServices);
37
- registerPattern(plugin, '/接龙 [action:word]', '成语接龙(中文)', getServices);
38
- }
39
-
40
- async function resolveChoice(
41
- message: Message<any>,
42
- services: SessionService,
43
- ): Promise<{ sessionId: string; choiceId: string } | null> {
44
- return resolveGameChoice({
45
- message,
46
- gamePrefix: CHAIN_PREFIX,
47
- validChoiceIds: VALID_CHOICES,
48
- getById: (id) => services.getById(id),
49
- getActiveForUser: (ch, uid) => services.getActiveForUser(ch, uid),
50
- getByBoardMessageId: (mid) => services.getActiveByBoardMessageId(mid),
51
- });
52
- }
53
-
54
- export function registerInteractive(plugin: Plugin, getServices: () => SessionService | null): void {
55
- plugin.registerInteractiveHandler(`${CHAIN_PREFIX}:`, async (message) => {
56
- const services = getServices();
57
- if (!services) return false;
58
- const choice = await resolveChoice(message, services);
59
- if (!choice) return false;
60
- const err = await handleChoice(plugin, services, message, choice.sessionId, choice.choiceId);
61
- if (err) await message.$reply?.(err);
62
- return true;
63
- });
64
- }
65
-
66
- export function registerTextMiddleware(plugin: Plugin, getServices: () => SessionService | null): void {
67
- registerGameTextMiddleware(plugin, async (message, next) => {
68
- const services = getServices();
69
- if (!services) return next();
70
-
71
- const action = getActionFromMessage(message);
72
- if (action?.payload.startsWith(`${CHAIN_PREFIX}:`)) return next();
73
-
74
- const raw = message.$raw?.trim() ?? '';
75
- if (!raw) return next();
76
-
77
- const ch = channelKey(message);
78
- const payloadFromText = resolveGameTextPayload(raw);
79
- if (payloadFromText?.startsWith(`${CHAIN_PREFIX}:`)) {
80
- const parsed = parseChoicePayload(payloadFromText, CHAIN_PREFIX);
81
- if (parsed) {
82
- const session = await services.getById(parsed.sessionId);
83
- if (session?.channel_key === ch) {
84
- const err = await handleChoice(plugin, services, message, parsed.sessionId, parsed.choiceId);
85
- if (err) await message.$reply?.(err);
86
- return;
87
- }
88
- }
89
- }
90
-
91
- const session = await services.getActiveForUser(ch, message.$sender.id);
92
- if (!session) return next();
93
-
94
- if (session.status === 'active') {
95
- const map = buildChoiceFallbackMap(CHAIN_PREFIX, session.id, [
96
- { id: 'hint', label: '提示' },
97
- { id: 'skip', label: '跳过' },
98
- { id: 'quit', label: '认输' },
99
- ]);
100
- const payload = resolveGameTextPayload(raw, map);
101
- const parsed = payload ? parseChoicePayload(payload, CHAIN_PREFIX) : null;
102
- if (parsed?.sessionId === session.id) {
103
- const err = await handleChoice(plugin, services, message, session.id, parsed.choiceId);
104
- if (err) await message.$reply?.(err);
105
- return;
106
- }
107
- }
108
-
109
- if (/^[\u4e00-\u9fff]{2,8}$/.test(raw)) {
110
- await processIdiomText(plugin, services, message, raw);
111
- return;
112
- }
113
-
114
- return next();
115
- }, 'idiom-chain:text');
116
- }
@@ -1,32 +0,0 @@
1
- import { getPlugin } from 'zhin.js';
2
- import { ensureGameHubService } from '@zhin.js/game-shared';
3
- import { idiomCount } from './engine.js';
4
- import { runChainCommand, CHAIN_HELP } from './chain-command.js';
5
- import type { SessionService } from './session-service.js';
6
-
7
- export function registerChainHub(getServices: () => SessionService | null): () => void {
8
- const plugin = getPlugin();
9
- ensureGameHubService(plugin);
10
- return plugin.registerGame({
11
- id: 'chain',
12
- title: '成语接龙',
13
- icon: '📜',
14
- description: `四字成语接龙(同音/同字),词库 ${idiomCount()} 条`,
15
- commandPrefix: '/接龙',
16
- quickStart: 'start_pinyin',
17
- aliases: ['chain'],
18
- menus: [
19
- { id: 'start_pinyin', label: '🎮 同音接龙', style: 'primary' },
20
- { id: 'start_char', label: '📝 同字接龙' },
21
- { id: 'continue', label: '🔄 继续' },
22
- { id: 'help', label: '📖 玩法说明' },
23
- ],
24
- runAction: async (actionId, ctx) => {
25
- const services = getServices();
26
- if (!services) return '成语接龙需要启用 database 配置。';
27
- return runChainCommand(ctx.plugin, services, ctx.message, actionId);
28
- },
29
- });
30
- }
31
-
32
- export { CHAIN_HELP };