@zhin.js/plugin-word-riddle 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 (64) hide show
  1. package/commands/riddle/[action:string=].ts +15 -0
  2. package/lib/engine.d.ts +0 -1
  3. package/lib/game-flow.d.ts +6 -7
  4. package/lib/game-flow.js +22 -15
  5. package/lib/game-flow.js.map +1 -1
  6. package/lib/index.d.ts +8 -2
  7. package/lib/index.js +8 -25
  8. package/lib/index.js.map +1 -1
  9. package/lib/memory-db.d.ts +6 -0
  10. package/lib/memory-db.js +18 -0
  11. package/lib/memory-db.js.map +1 -0
  12. package/lib/models.d.ts +5 -4
  13. package/lib/models.js +2 -2
  14. package/lib/models.js.map +1 -1
  15. package/lib/riddle-command.d.ts +4 -3
  16. package/lib/riddle-command.js +5 -1
  17. package/lib/riddle-command.js.map +1 -1
  18. package/lib/riddle-provider.d.ts +0 -1
  19. package/lib/riddle-provider.js +1 -1
  20. package/lib/riddle-provider.js.map +1 -1
  21. package/lib/riddles-catalog.d.ts +0 -1
  22. package/lib/runtime-store.d.ts +6 -0
  23. package/lib/runtime-store.js +7 -0
  24. package/lib/runtime-store.js.map +1 -0
  25. package/lib/session-service.d.ts +1 -3
  26. package/lib/session-service.js +1 -4
  27. package/lib/session-service.js.map +1 -1
  28. package/lib/view.d.ts +1 -2
  29. package/lib/view.js +1 -1
  30. package/lib/view.js.map +1 -1
  31. package/middlewares/riddle-alias.ts +18 -0
  32. package/middlewares/riddle-text.ts +75 -0
  33. package/package.json +36 -10
  34. package/plugin.ts +64 -0
  35. package/schema.json +6 -0
  36. package/src/game-flow.ts +26 -22
  37. package/src/index.ts +9 -30
  38. package/src/memory-db.ts +22 -0
  39. package/src/models.ts +7 -4
  40. package/src/riddle-command.ts +12 -3
  41. package/src/riddle-provider.ts +1 -1
  42. package/src/runtime-store.ts +9 -0
  43. package/src/session-service.ts +2 -5
  44. package/src/view.ts +2 -2
  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 -32
  54. package/lib/hub-register.js.map +0 -1
  55. package/lib/index.d.ts.map +0 -1
  56. package/lib/models.d.ts.map +0 -1
  57. package/lib/riddle-command.d.ts.map +0 -1
  58. package/lib/riddle-provider.d.ts.map +0 -1
  59. package/lib/riddles-catalog.d.ts.map +0 -1
  60. package/lib/session-service.d.ts.map +0 -1
  61. package/lib/view.d.ts.map +0 -1
  62. package/plugin.yml +0 -2
  63. package/src/commands.ts +0 -116
  64. package/src/hub-register.ts +0 -34
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-service.d.ts","sourceRoot":"","sources":["../src/session-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAgB,MAAM,SAAS,CAAC;AAExF,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAQ/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,MAAM,EAAE,CASvE;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,cAAc;IAEzC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAKrE,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAMnF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAIrD,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAS9E,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA6BjF,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAalD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CAEjE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAE5E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAGxE"}
package/lib/view.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,QAAA,MAAM,SAAS,IAAI,CAAC;AAEpB,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gBAAgB,EACzB,UAAU,GAAE,MAAM,EAAO,EACzB,WAAW,CAAC,EAAE,MAAM,GACnB,WAAW,GAAG,MAAM,CAgDtB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/plugin.yml DELETED
@@ -1,2 +0,0 @@
1
- name: "@zhin.js/plugin-word-riddle"
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
- normalizeRiddleAction,
6
- parseChoicePayload,
7
- registerGameTextMiddleware,
8
- resolveGameChoice,
9
- resolveGameTextPayload,
10
- } from '@zhin.js/game-shared';
11
- import { handleChoice, processAnswerText, RIDDLE_PREFIX } from './game-flow.js';
12
- import { runRiddleCommand } from './riddle-command.js';
13
- import type { SessionService } from './session-service.js';
14
-
15
- const VALID_CHOICES = ['hint', 'skip', 'quit', 'restart_char', 'restart_idiom'] 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 runRiddleCommand(plugin, services, message, normalizeRiddleAction(raw));
31
- }),
32
- );
33
- }
34
-
35
- export function registerCommands(plugin: Plugin, getServices: () => SessionService | null): void {
36
- registerPattern(plugin, '/riddle [action:word]', '猜谜(riddle)', 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: RIDDLE_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(`${RIDDLE_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 (typeof err === 'string') 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(`${RIDDLE_PREFIX}:`)) return next();
73
-
74
- const ch = channelKey(message);
75
- const raw = message.$raw?.trim() ?? '';
76
- if (!raw) return next();
77
-
78
- const payloadFromText = resolveGameTextPayload(raw);
79
- if (payloadFromText?.startsWith(`${RIDDLE_PREFIX}:`)) {
80
- const parsed = parseChoicePayload(payloadFromText, RIDDLE_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 (typeof err === 'string') 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(RIDDLE_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, RIDDLE_PREFIX) : null;
102
- if (parsed?.sessionId === session.id) {
103
- const err = await handleChoice(plugin, services, message, session.id, parsed.choiceId);
104
- if (typeof err === 'string') await message.$reply?.(err);
105
- return;
106
- }
107
- }
108
-
109
- if (/^[\u4e00-\u9fff]{1,8}$/.test(raw)) {
110
- await processAnswerText(plugin, services, message, raw);
111
- return;
112
- }
113
-
114
- return next();
115
- }, 'word-riddle:text');
116
- }
@@ -1,34 +0,0 @@
1
- import { getPlugin } from 'zhin.js';
2
- import { ensureGameHubService } from '@zhin.js/game-shared';
3
- import { riddleCount } from './riddles-catalog.js';
4
- import { runRiddleCommand, RIDDLE_HELP } from './riddle-command.js';
5
- import type { SessionService } from './session-service.js';
6
-
7
- const counts = riddleCount();
8
-
9
- export function registerRiddleHub(getServices: () => SessionService | null): () => void {
10
- const plugin = getPlugin();
11
- ensureGameHubService(plugin);
12
- return plugin.registerGame({
13
- id: 'riddle',
14
- title: '猜谜',
15
- icon: '🧩',
16
- description: `字谜 ${counts.char.toLocaleString('zh-CN')} 题 + 成语 ${counts.idiom.toLocaleString('zh-CN')} 题`,
17
- commandPrefix: '/猜谜',
18
- quickStart: '开始',
19
- aliases: ['riddle'],
20
- menus: [
21
- { id: 'char', label: '🔤 字谜模式', style: 'primary' },
22
- { id: 'idiom', label: '📜 成语模式' },
23
- { id: 'continue', label: '🔄 继续' },
24
- { id: 'help', label: '📖 玩法说明' },
25
- ],
26
- runAction: async (actionId, ctx) => {
27
- const services = getServices();
28
- if (!services) return '猜谜需要启用 database 配置。';
29
- return runRiddleCommand(ctx.plugin, services, ctx.message, actionId === 'start' ? 'char' : actionId);
30
- },
31
- });
32
- }
33
-
34
- export { RIDDLE_HELP };