@dsh-plugin/dsh-synapse 0.1.0-dev.41044228975 → 0.1.0

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 (74) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +0 -14
  3. package/package.json +1 -1
  4. package/vendor/gugle-chat-bot/LICENSE +661 -661
  5. package/vendor/gugle-chat-bot/package.json +57 -57
  6. package/vendor/gugle-chat-bot/src/allow-rule.yml +9345 -9345
  7. package/vendor/gugle-chat-bot/src/api.json +4284 -4284
  8. package/vendor/gugle-chat-bot/src/command/index.ts +141 -141
  9. package/vendor/gugle-chat-bot/src/config/features.ts +547 -547
  10. package/vendor/gugle-chat-bot/src/config/index.ts +184 -184
  11. package/vendor/gugle-chat-bot/src/config/manager.ts +356 -356
  12. package/vendor/gugle-chat-bot/src/constants/index.ts +13 -13
  13. package/vendor/gugle-chat-bot/src/custom.ts +548 -548
  14. package/vendor/gugle-chat-bot/src/event/index.ts +118 -118
  15. package/vendor/gugle-chat-bot/src/features/admin/index.ts +414 -414
  16. package/vendor/gugle-chat-bot/src/features/bili/image/impl/video.ts +39 -39
  17. package/vendor/gugle-chat-bot/src/features/bili/image/index.ts +37 -37
  18. package/vendor/gugle-chat-bot/src/features/bili/index.ts +65 -65
  19. package/vendor/gugle-chat-bot/src/features/bili/template/style/video.css +97 -97
  20. package/vendor/gugle-chat-bot/src/features/bili/template/video.html +56 -56
  21. package/vendor/gugle-chat-bot/src/features/discord-bridge/index.ts +1128 -1128
  22. package/vendor/gugle-chat-bot/src/features/discord-bridge/markdown.ts +105 -105
  23. package/vendor/gugle-chat-bot/src/features/discord-bridge/slash.ts +355 -355
  24. package/vendor/gugle-chat-bot/src/features/discord-bridge/source.ts +96 -96
  25. package/vendor/gugle-chat-bot/src/features/discord-bridge/template/message.html +14 -14
  26. package/vendor/gugle-chat-bot/src/features/discord-bridge/template/style/message.css +144 -144
  27. package/vendor/gugle-chat-bot/src/features/github/api.ts +93 -93
  28. package/vendor/gugle-chat-bot/src/features/github/binding.ts +161 -161
  29. package/vendor/gugle-chat-bot/src/features/github/image/impl/issue.ts +132 -132
  30. package/vendor/gugle-chat-bot/src/features/github/image/impl/pr.ts +144 -144
  31. package/vendor/gugle-chat-bot/src/features/github/image/impl/release.ts +160 -160
  32. package/vendor/gugle-chat-bot/src/features/github/image/index.ts +310 -310
  33. package/vendor/gugle-chat-bot/src/features/github/index.ts +302 -302
  34. package/vendor/gugle-chat-bot/src/features/github/template/issue.html +118 -118
  35. package/vendor/gugle-chat-bot/src/features/github/template/pull_request.html +125 -125
  36. package/vendor/gugle-chat-bot/src/features/github/template/release.html +53 -53
  37. package/vendor/gugle-chat-bot/src/features/github/template/style/issue.css +468 -468
  38. package/vendor/gugle-chat-bot/src/features/github/template/style/pull_request.css +468 -468
  39. package/vendor/gugle-chat-bot/src/features/github/template/style/release.css +412 -412
  40. package/vendor/gugle-chat-bot/src/features/hermes/client.ts +184 -184
  41. package/vendor/gugle-chat-bot/src/features/hermes/config.ts +210 -210
  42. package/vendor/gugle-chat-bot/src/features/hermes/context.ts +67 -67
  43. package/vendor/gugle-chat-bot/src/features/hermes/history.ts +86 -86
  44. package/vendor/gugle-chat-bot/src/features/hermes/index.ts +1533 -1533
  45. package/vendor/gugle-chat-bot/src/features/hermes/message.ts +319 -319
  46. package/vendor/gugle-chat-bot/src/features/hermes/reaction.ts +181 -181
  47. package/vendor/gugle-chat-bot/src/features/hermes/render.ts +118 -118
  48. package/vendor/gugle-chat-bot/src/features/hermes/reply-units.ts +331 -331
  49. package/vendor/gugle-chat-bot/src/features/hermes/skills.ts +406 -406
  50. package/vendor/gugle-chat-bot/src/features/hermes/template/approval.html +30 -30
  51. package/vendor/gugle-chat-bot/src/features/hermes/template/progress.html +21 -21
  52. package/vendor/gugle-chat-bot/src/features/hermes/template/style/approval.css +81 -81
  53. package/vendor/gugle-chat-bot/src/features/hermes/template/style/progress.css +120 -120
  54. package/vendor/gugle-chat-bot/src/features/hermes/trigger.ts +86 -86
  55. package/vendor/gugle-chat-bot/src/features/hermes/types.ts +327 -327
  56. package/vendor/gugle-chat-bot/src/features/management/index.ts +156 -156
  57. package/vendor/gugle-chat-bot/src/features/minecraft/index.ts +127 -127
  58. package/vendor/gugle-chat-bot/src/features/modrinth/index.ts +71 -71
  59. package/vendor/gugle-chat-bot/src/features/parentheses/index.ts +117 -117
  60. package/vendor/gugle-chat-bot/src/features/peak-valley-timer/index.ts +451 -451
  61. package/vendor/gugle-chat-bot/src/features/poke/index.ts +24 -24
  62. package/vendor/gugle-chat-bot/src/features/version-tracker/index.ts +77 -77
  63. package/vendor/gugle-chat-bot/src/features/welcome/index.ts +57 -57
  64. package/vendor/gugle-chat-bot/src/github-ip.json +5814 -5814
  65. package/vendor/gugle-chat-bot/src/image/index.ts +278 -278
  66. package/vendor/gugle-chat-bot/src/index.ts +695 -695
  67. package/vendor/gugle-chat-bot/src/logger/index.ts +54 -54
  68. package/vendor/gugle-chat-bot/src/result.json +359 -359
  69. package/vendor/gugle-chat-bot/src/type/bili.d.ts +825 -825
  70. package/vendor/gugle-chat-bot/src/type/event.d.ts +146 -146
  71. package/vendor/gugle-chat-bot/src/type/github.d.ts +446 -446
  72. package/vendor/gugle-chat-bot/src/type/index.d.ts +254 -254
  73. package/vendor/gugle-chat-bot/tsconfig.json +46 -46
  74. package/scripts/dump-npm-latest.mjs +0 -30
@@ -1,141 +1,141 @@
1
- import { CommandManager, CommandSource } from 'gugle-command';
2
-
3
- /**
4
- * 平台无关的命令源抽象。
5
- *
6
- * 背景:`gugle-command` 的 `CommandSource` 只有 success/fail/getName/hasPermission 四个方法,
7
- * 命令实现若直接 `instanceof GroupMsgCommandSource` 判定,就只能服务 QQ 群消息。
8
- * 这里扩展出跨平台需要的最小能力集,让同一套命令实现既能在 QQ 群、也能在 Discord 频道执行。
9
- */
10
- export interface BotCommandSource extends CommandSource {
11
- /**
12
- * 调用者平台内唯一标识:
13
- * - QQ 群消息:纯数字 QQ 号字符串(如 `2308465862`)
14
- * - Discord 消息:`dc:<用户ID>`(如 `dc:123456789012345678`)
15
- *
16
- * 用于 GitHub 绑定等需要持久化用户身份的场景;`dc:` 前缀保证与纯数字 QQ 号不会冲突。
17
- */
18
- getUserId(): string;
19
-
20
- /**
21
- * 消息所在群/频道在当前平台上对应的互通 QQ 群号。
22
- * QQ 群消息返回自身群号;Discord 频道返回该频道桥接配置里的 QQ 群号;
23
- * 无归属群(未配置互通的 Discord 频道等)返回 undefined。
24
- */
25
- getGroupId(): number | undefined;
26
-
27
- /**
28
- * 是否为管理员:QQ 侧复用 management operators 白名单;
29
- * Discord 侧为服务器拥有者或拥有管理服务器/管理员权限者。
30
- */
31
- isAdmin(): boolean;
32
- }
33
-
34
- /** 判断命令源是否具备 BotCommandSource 能力(鸭子类型,跨模块实例也成立) */
35
- export function isBotCommandSource(source: CommandSource | undefined): source is BotCommandSource {
36
- if (!source) return false;
37
- const candidate = source as Partial<BotCommandSource>;
38
- return (
39
- typeof candidate.getUserId === 'function' &&
40
- typeof candidate.getGroupId === 'function' &&
41
- typeof candidate.isAdmin === 'function'
42
- );
43
- }
44
-
45
- /**
46
- * 由命令源推导「操作者标识」,供需要区分平台的管理逻辑使用。
47
- *
48
- * 背景:`executeCommand` 会把命令源包进 `FailOnceCommandSource` 代理,
49
- * 命令实现里 `source instanceof GroupMsgCommandSource` 恒为 false——曾因此让
50
- * QQ 管理员执行 /pardon 被误判成 Discord 用户而失败。这里改为按 BotCommandSource
51
- * 的 id 约定判定,不依赖实例类型:
52
- * - 纯数字 → QQ 号,返回 number(Management 内部再校验 operators 白名单);
53
- * - `dc:<用户ID>` → Discord 用户,原样返回字符串(服务器管理员身份已在命令源层校验)。
54
- */
55
- export function resolveOperatorId(source: BotCommandSource): number | string {
56
- const userId = source.getUserId();
57
- return /^\d+$/.test(userId) ? Number(userId) : userId;
58
- }
59
-
60
- /**
61
- * 把命令文本规范化为 gugle-command 可执行的形式。
62
- *
63
- * gugle-command 固定使用 `/` 前缀;Discord 客户端会把以 `/` 开头的内容当作斜杠命令输入,
64
- * 因此 Discord 侧额外支持 `!` 前缀作为兜底,统一在这里转换。
65
- */
66
- export function normalizeCommandText(text: string): string {
67
- return text.startsWith('!') ? `/${text.slice(1)}` : text;
68
- }
69
-
70
- /**
71
- * 失败去重代理:同一命令执行周期内,`fail` 只向用户上报第一次。
72
- *
73
- * 背景:gugle-command 的 `CommandNode.parse()` 在深层匹配失败时已调用一次
74
- * `source.fail('Invalid command')`,`CommandManager.execute()` 遍历完所有命名空间后
75
- * 又兜底调用一次——`/help abc` 这类「命令存在但参数多余」的输入会向用户回复两条
76
- * Invalid command。代理只放行第一次 fail(success 不受影响),修复重复回复。
77
- *
78
- * 注意:getUserId/getGroupId/isAdmin 按内部源是否有该方法条件绑定,
79
- * 保证 isBotCommandSource 鸭子类型检查对代理前后结果一致。
80
- */
81
- class FailOnceCommandSource implements CommandSource {
82
- private readonly inner: CommandSource;
83
- private failed = false;
84
-
85
- public getUserId?: () => string;
86
- public getGroupId?: () => number | undefined;
87
- public isAdmin?: () => boolean;
88
-
89
- public constructor(inner: CommandSource) {
90
- this.inner = inner;
91
- if (isBotCommandSource(inner)) {
92
- this.getUserId = () => inner.getUserId();
93
- this.getGroupId = () => inner.getGroupId();
94
- this.isAdmin = () => inner.isAdmin();
95
- }
96
- }
97
-
98
- public success(message: string): void {
99
- this.inner.success(message);
100
- }
101
-
102
- public fail(message: string): void {
103
- if (this.failed) return;
104
- this.failed = true;
105
- this.inner.fail(message);
106
- }
107
-
108
- public getName(): string {
109
- return this.inner.getName();
110
- }
111
-
112
- public hasPermission(permission: string): boolean {
113
- return this.inner.hasPermission(permission);
114
- }
115
- }
116
-
117
- /**
118
- * 执行命令文本(经 FailOnce 代理,重复失败提示只上报一次)。
119
- * 所有命令分发入口(QQ 群、Discord 文本、Discord 交互)统一走这里。
120
- */
121
- export function executeCommand(manager: CommandManager, source: CommandSource, command: string): void {
122
- manager.execute(new FailOnceCommandSource(source), command);
123
- }
124
-
125
- /**
126
- * 以精确 token 序列执行命令(不经字符串切分)。
127
- *
128
- * 用途:Discord 原生斜杠命令交互——参数值由 Discord 客户端按 option 给出,
129
- * 可能包含空格(如 /wiki 的查询词),若拼回字符串再经 gugle-command 按空格切分
130
- * 会被打散。这里把 token 逆序后直接喂给各命名空间根节点的 parse:
131
- * parse 逐 token 弹出匹配,字符串参数保持完整。
132
- *
133
- * @param tokens 完整 token 序列,如 ['github', 'bind', 'Gugle'] 或 ['wiki', '下界 合金']
134
- */
135
- export function executeCommandTokens(manager: CommandManager, source: CommandSource, tokens: string[]): void {
136
- const wrapped = new FailOnceCommandSource(source);
137
- for (const root of manager.roots.values()) {
138
- if (root.parse([...tokens].reverse(), wrapped)) return;
139
- }
140
- wrapped.fail('Invalid command');
141
- }
1
+ import { CommandManager, CommandSource } from 'gugle-command';
2
+
3
+ /**
4
+ * 平台无关的命令源抽象。
5
+ *
6
+ * 背景:`gugle-command` 的 `CommandSource` 只有 success/fail/getName/hasPermission 四个方法,
7
+ * 命令实现若直接 `instanceof GroupMsgCommandSource` 判定,就只能服务 QQ 群消息。
8
+ * 这里扩展出跨平台需要的最小能力集,让同一套命令实现既能在 QQ 群、也能在 Discord 频道执行。
9
+ */
10
+ export interface BotCommandSource extends CommandSource {
11
+ /**
12
+ * 调用者平台内唯一标识:
13
+ * - QQ 群消息:纯数字 QQ 号字符串(如 `2308465862`)
14
+ * - Discord 消息:`dc:<用户ID>`(如 `dc:123456789012345678`)
15
+ *
16
+ * 用于 GitHub 绑定等需要持久化用户身份的场景;`dc:` 前缀保证与纯数字 QQ 号不会冲突。
17
+ */
18
+ getUserId(): string;
19
+
20
+ /**
21
+ * 消息所在群/频道在当前平台上对应的互通 QQ 群号。
22
+ * QQ 群消息返回自身群号;Discord 频道返回该频道桥接配置里的 QQ 群号;
23
+ * 无归属群(未配置互通的 Discord 频道等)返回 undefined。
24
+ */
25
+ getGroupId(): number | undefined;
26
+
27
+ /**
28
+ * 是否为管理员:QQ 侧复用 management operators 白名单;
29
+ * Discord 侧为服务器拥有者或拥有管理服务器/管理员权限者。
30
+ */
31
+ isAdmin(): boolean;
32
+ }
33
+
34
+ /** 判断命令源是否具备 BotCommandSource 能力(鸭子类型,跨模块实例也成立) */
35
+ export function isBotCommandSource(source: CommandSource | undefined): source is BotCommandSource {
36
+ if (!source) return false;
37
+ const candidate = source as Partial<BotCommandSource>;
38
+ return (
39
+ typeof candidate.getUserId === 'function' &&
40
+ typeof candidate.getGroupId === 'function' &&
41
+ typeof candidate.isAdmin === 'function'
42
+ );
43
+ }
44
+
45
+ /**
46
+ * 由命令源推导「操作者标识」,供需要区分平台的管理逻辑使用。
47
+ *
48
+ * 背景:`executeCommand` 会把命令源包进 `FailOnceCommandSource` 代理,
49
+ * 命令实现里 `source instanceof GroupMsgCommandSource` 恒为 false——曾因此让
50
+ * QQ 管理员执行 /pardon 被误判成 Discord 用户而失败。这里改为按 BotCommandSource
51
+ * 的 id 约定判定,不依赖实例类型:
52
+ * - 纯数字 → QQ 号,返回 number(Management 内部再校验 operators 白名单);
53
+ * - `dc:<用户ID>` → Discord 用户,原样返回字符串(服务器管理员身份已在命令源层校验)。
54
+ */
55
+ export function resolveOperatorId(source: BotCommandSource): number | string {
56
+ const userId = source.getUserId();
57
+ return /^\d+$/.test(userId) ? Number(userId) : userId;
58
+ }
59
+
60
+ /**
61
+ * 把命令文本规范化为 gugle-command 可执行的形式。
62
+ *
63
+ * gugle-command 固定使用 `/` 前缀;Discord 客户端会把以 `/` 开头的内容当作斜杠命令输入,
64
+ * 因此 Discord 侧额外支持 `!` 前缀作为兜底,统一在这里转换。
65
+ */
66
+ export function normalizeCommandText(text: string): string {
67
+ return text.startsWith('!') ? `/${text.slice(1)}` : text;
68
+ }
69
+
70
+ /**
71
+ * 失败去重代理:同一命令执行周期内,`fail` 只向用户上报第一次。
72
+ *
73
+ * 背景:gugle-command 的 `CommandNode.parse()` 在深层匹配失败时已调用一次
74
+ * `source.fail('Invalid command')`,`CommandManager.execute()` 遍历完所有命名空间后
75
+ * 又兜底调用一次——`/help abc` 这类「命令存在但参数多余」的输入会向用户回复两条
76
+ * Invalid command。代理只放行第一次 fail(success 不受影响),修复重复回复。
77
+ *
78
+ * 注意:getUserId/getGroupId/isAdmin 按内部源是否有该方法条件绑定,
79
+ * 保证 isBotCommandSource 鸭子类型检查对代理前后结果一致。
80
+ */
81
+ class FailOnceCommandSource implements CommandSource {
82
+ private readonly inner: CommandSource;
83
+ private failed = false;
84
+
85
+ public getUserId?: () => string;
86
+ public getGroupId?: () => number | undefined;
87
+ public isAdmin?: () => boolean;
88
+
89
+ public constructor(inner: CommandSource) {
90
+ this.inner = inner;
91
+ if (isBotCommandSource(inner)) {
92
+ this.getUserId = () => inner.getUserId();
93
+ this.getGroupId = () => inner.getGroupId();
94
+ this.isAdmin = () => inner.isAdmin();
95
+ }
96
+ }
97
+
98
+ public success(message: string): void {
99
+ this.inner.success(message);
100
+ }
101
+
102
+ public fail(message: string): void {
103
+ if (this.failed) return;
104
+ this.failed = true;
105
+ this.inner.fail(message);
106
+ }
107
+
108
+ public getName(): string {
109
+ return this.inner.getName();
110
+ }
111
+
112
+ public hasPermission(permission: string): boolean {
113
+ return this.inner.hasPermission(permission);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * 执行命令文本(经 FailOnce 代理,重复失败提示只上报一次)。
119
+ * 所有命令分发入口(QQ 群、Discord 文本、Discord 交互)统一走这里。
120
+ */
121
+ export function executeCommand(manager: CommandManager, source: CommandSource, command: string): void {
122
+ manager.execute(new FailOnceCommandSource(source), command);
123
+ }
124
+
125
+ /**
126
+ * 以精确 token 序列执行命令(不经字符串切分)。
127
+ *
128
+ * 用途:Discord 原生斜杠命令交互——参数值由 Discord 客户端按 option 给出,
129
+ * 可能包含空格(如 /wiki 的查询词),若拼回字符串再经 gugle-command 按空格切分
130
+ * 会被打散。这里把 token 逆序后直接喂给各命名空间根节点的 parse:
131
+ * parse 逐 token 弹出匹配,字符串参数保持完整。
132
+ *
133
+ * @param tokens 完整 token 序列,如 ['github', 'bind', 'Gugle'] 或 ['wiki', '下界 合金']
134
+ */
135
+ export function executeCommandTokens(manager: CommandManager, source: CommandSource, tokens: string[]): void {
136
+ const wrapped = new FailOnceCommandSource(source);
137
+ for (const root of manager.roots.values()) {
138
+ if (root.parse([...tokens].reverse(), wrapped)) return;
139
+ }
140
+ wrapped.fail('Invalid command');
141
+ }