@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,105 +1,105 @@
1
- import MarkdownIt from 'markdown-it';
2
- // @ts-ignore markdown-it-emoji 未提供默认导出类型声明(full 预设,同时支持 :name: 与 Unicode emoji)
3
- import emoji from 'markdown-it-emoji';
4
- import { Message } from 'discord.js';
5
- import { Template, tryGenerateImage } from '@/image';
6
-
7
- /**
8
- * Discord markdown 工具:
9
- * - isDiscordMarkdown:启发式判断一段文本是否使用了 Discord markdown 语法
10
- * - escapeDiscord:发送纯文本前转义 markdown 特殊字符,避免被 Discord 误渲染
11
- * - renderDiscordMessageToImage:把 Discord 消息内容渲染为图片(base64),转发到 QQ 用
12
- */
13
-
14
- /** 启发式判定文本是否包含 Discord markdown 语法 */
15
- const DISCORD_MARKDOWN_PATTERNS: RegExp[] = [
16
- /\*\*[^*\n]+\*\*/, // **粗体**
17
- /(^|[\s((>])\*[^*\s][^*\n]*\*(?![*\w])/, // *斜体*(避免把 a*b*c 误判为 markdown)
18
- /__[^_\n]+__/, // __下划线__(CommonMark 会渲染为粗体,属已知偏差)
19
- /(^|[\s((>])_[^_\s][^_\n]*_(?![_\w])/, // _斜体_
20
- /~~[^~\n]+~~/, // ~~删除线~~
21
- /\|\|[^|\n]+\|\|/, // ||剧透||
22
- /```[\s\S]*?```/, // 代码块
23
- /`[^`\n]+`/, // 行内代码
24
- /^#{1,3}\s+\S/m, // # 标题(行首)
25
- /^>\s+\S/m, // > 引用(行首)
26
- /^\s*[-*+]\s+\S/m, // 无序列表
27
- /^\s*\d+\.\s+\S/m, // 有序列表
28
- /\[[^\]\n]+\]\([^)\n]+\)/, // [文字](链接)
29
- /<[@#][!&]?\d+>/, // <@id> / <@!id> / <#id>
30
- /<a?:\w{2,32}:\d+>/, // <a?:name:id> 自定义表情
31
- /^-{3,}\s*$/m // 分割线
32
- ];
33
-
34
- export function isDiscordMarkdown(text: string): boolean {
35
- return DISCORD_MARKDOWN_PATTERNS.some(pattern => pattern.test(text));
36
- }
37
-
38
- /** 转义 Discord markdown 特殊字符,使文本按原样(plain text)显示 */
39
- export function escapeDiscord(text: string): string {
40
- return text.replace(/([\\*_~`|>#-])/g, '\\$1');
41
- }
42
-
43
- /** HTML 转义(注入模板/渲染前处理用户文本) */
44
- export function escapeHtml(text: string): string {
45
- return text
46
- .replace(/&/g, '&amp;')
47
- .replace(/</g, '&lt;')
48
- .replace(/>/g, '&gt;')
49
- .replace(/"/g, '&quot;');
50
- }
51
-
52
- const md: MarkdownIt = new MarkdownIt({
53
- html: false,
54
- linkify: true,
55
- breaks: true
56
- }).use(emoji.full ?? emoji);
57
-
58
- /**
59
- * 把 Discord 消息文本渲染为 HTML 片段。
60
- * 先 HTML 转义,再把 Discord 特有语法(提及/频道/自定义表情/剧透)替换为等价 HTML,
61
- * 最后交给 markdown-it 渲染公共 markdown 部分。
62
- */
63
- export function renderDiscordMarkdownToHtml(content: string, message?: Message): string {
64
- let text = escapeHtml(content);
65
- // 剧透 ||x|| → 黑块(markdown-it 不认识该语法,先替换为 HTML)
66
- text = text.replace(/\|\|([\s\S]+?)\|\|/g, '<span class="spoiler">$1</span>');
67
- // 自定义表情 <a?:name:id>
68
- text = text.replace(/&lt;a?:(\w{2,32}):\d+&gt;/g, ':$1:');
69
- // 频道提及 <#id> → #频道名
70
- text = text.replace(/&lt;#(\d+)&gt;/g, (_match, id: string) => {
71
- const name = message?.guild?.channels.cache.get(id)?.name;
72
- return `<span class="mention">#${escapeHtml(name ?? id)}</span>`;
73
- });
74
- // 用户提及 <@id> / <@!id> → @昵称
75
- text = text.replace(/&lt;@!?(\d+)&gt;/g, (_match, id: string) => {
76
- const name =
77
- message?.mentions.members?.get(id)?.displayName ?? message?.mentions.users.get(id)?.username;
78
- return `<span class="mention">@${escapeHtml(name ?? id)}</span>`;
79
- });
80
- // 角色提及 <@&id> → @角色名
81
- text = text.replace(/&lt;@&amp;(\d+)&gt;/g, (_match, id: string) => {
82
- const name = message?.guild?.roles.cache.get(id)?.name;
83
- return `<span class="mention">@${escapeHtml(name ?? id)}</span>`;
84
- });
85
- return md.render(text);
86
- }
87
-
88
- /**
89
- * 把 Discord markdown 消息渲染成 PNG 图片(base64)。
90
- * header 为图片顶部来源行(【服务器|频道】昵称(用户名)),content 为消息正文。
91
- * 复用 src/image/index.ts 的共享 Chrome 截图队列。
92
- */
93
- export function renderDiscordMessageToImage(header: string, content: string, message?: Message): Promise<string> {
94
- return new Promise<string>((resolve, reject) => {
95
- const htmlFragment = renderDiscordMarkdownToHtml(content, message);
96
- const template = Template.load('message', 'src/features/discord-bridge/template')
97
- .arg('header', escapeHtml(header))
98
- .arg('content', htmlFragment);
99
- const templateFile = template.file();
100
- template
101
- .handler()
102
- .then(html => tryGenerateImage(resolve, reject, html, 640, templateFile))
103
- .catch(reject);
104
- });
105
- }
1
+ import MarkdownIt from 'markdown-it';
2
+ // @ts-ignore markdown-it-emoji 未提供默认导出类型声明(full 预设,同时支持 :name: 与 Unicode emoji)
3
+ import emoji from 'markdown-it-emoji';
4
+ import { Message } from 'discord.js';
5
+ import { Template, tryGenerateImage } from '@/image';
6
+
7
+ /**
8
+ * Discord markdown 工具:
9
+ * - isDiscordMarkdown:启发式判断一段文本是否使用了 Discord markdown 语法
10
+ * - escapeDiscord:发送纯文本前转义 markdown 特殊字符,避免被 Discord 误渲染
11
+ * - renderDiscordMessageToImage:把 Discord 消息内容渲染为图片(base64),转发到 QQ 用
12
+ */
13
+
14
+ /** 启发式判定文本是否包含 Discord markdown 语法 */
15
+ const DISCORD_MARKDOWN_PATTERNS: RegExp[] = [
16
+ /\*\*[^*\n]+\*\*/, // **粗体**
17
+ /(^|[\s((>])\*[^*\s][^*\n]*\*(?![*\w])/, // *斜体*(避免把 a*b*c 误判为 markdown)
18
+ /__[^_\n]+__/, // __下划线__(CommonMark 会渲染为粗体,属已知偏差)
19
+ /(^|[\s((>])_[^_\s][^_\n]*_(?![_\w])/, // _斜体_
20
+ /~~[^~\n]+~~/, // ~~删除线~~
21
+ /\|\|[^|\n]+\|\|/, // ||剧透||
22
+ /```[\s\S]*?```/, // 代码块
23
+ /`[^`\n]+`/, // 行内代码
24
+ /^#{1,3}\s+\S/m, // # 标题(行首)
25
+ /^>\s+\S/m, // > 引用(行首)
26
+ /^\s*[-*+]\s+\S/m, // 无序列表
27
+ /^\s*\d+\.\s+\S/m, // 有序列表
28
+ /\[[^\]\n]+\]\([^)\n]+\)/, // [文字](链接)
29
+ /<[@#][!&]?\d+>/, // <@id> / <@!id> / <#id>
30
+ /<a?:\w{2,32}:\d+>/, // <a?:name:id> 自定义表情
31
+ /^-{3,}\s*$/m // 分割线
32
+ ];
33
+
34
+ export function isDiscordMarkdown(text: string): boolean {
35
+ return DISCORD_MARKDOWN_PATTERNS.some(pattern => pattern.test(text));
36
+ }
37
+
38
+ /** 转义 Discord markdown 特殊字符,使文本按原样(plain text)显示 */
39
+ export function escapeDiscord(text: string): string {
40
+ return text.replace(/([\\*_~`|>#-])/g, '\\$1');
41
+ }
42
+
43
+ /** HTML 转义(注入模板/渲染前处理用户文本) */
44
+ export function escapeHtml(text: string): string {
45
+ return text
46
+ .replace(/&/g, '&amp;')
47
+ .replace(/</g, '&lt;')
48
+ .replace(/>/g, '&gt;')
49
+ .replace(/"/g, '&quot;');
50
+ }
51
+
52
+ const md: MarkdownIt = new MarkdownIt({
53
+ html: false,
54
+ linkify: true,
55
+ breaks: true
56
+ }).use(emoji.full ?? emoji);
57
+
58
+ /**
59
+ * 把 Discord 消息文本渲染为 HTML 片段。
60
+ * 先 HTML 转义,再把 Discord 特有语法(提及/频道/自定义表情/剧透)替换为等价 HTML,
61
+ * 最后交给 markdown-it 渲染公共 markdown 部分。
62
+ */
63
+ export function renderDiscordMarkdownToHtml(content: string, message?: Message): string {
64
+ let text = escapeHtml(content);
65
+ // 剧透 ||x|| → 黑块(markdown-it 不认识该语法,先替换为 HTML)
66
+ text = text.replace(/\|\|([\s\S]+?)\|\|/g, '<span class="spoiler">$1</span>');
67
+ // 自定义表情 <a?:name:id>
68
+ text = text.replace(/&lt;a?:(\w{2,32}):\d+&gt;/g, ':$1:');
69
+ // 频道提及 <#id> → #频道名
70
+ text = text.replace(/&lt;#(\d+)&gt;/g, (_match, id: string) => {
71
+ const name = message?.guild?.channels.cache.get(id)?.name;
72
+ return `<span class="mention">#${escapeHtml(name ?? id)}</span>`;
73
+ });
74
+ // 用户提及 <@id> / <@!id> → @昵称
75
+ text = text.replace(/&lt;@!?(\d+)&gt;/g, (_match, id: string) => {
76
+ const name =
77
+ message?.mentions.members?.get(id)?.displayName ?? message?.mentions.users.get(id)?.username;
78
+ return `<span class="mention">@${escapeHtml(name ?? id)}</span>`;
79
+ });
80
+ // 角色提及 <@&id> → @角色名
81
+ text = text.replace(/&lt;@&amp;(\d+)&gt;/g, (_match, id: string) => {
82
+ const name = message?.guild?.roles.cache.get(id)?.name;
83
+ return `<span class="mention">@${escapeHtml(name ?? id)}</span>`;
84
+ });
85
+ return md.render(text);
86
+ }
87
+
88
+ /**
89
+ * 把 Discord markdown 消息渲染成 PNG 图片(base64)。
90
+ * header 为图片顶部来源行(【服务器|频道】昵称(用户名)),content 为消息正文。
91
+ * 复用 src/image/index.ts 的共享 Chrome 截图队列。
92
+ */
93
+ export function renderDiscordMessageToImage(header: string, content: string, message?: Message): Promise<string> {
94
+ return new Promise<string>((resolve, reject) => {
95
+ const htmlFragment = renderDiscordMarkdownToHtml(content, message);
96
+ const template = Template.load('message', 'src/features/discord-bridge/template')
97
+ .arg('header', escapeHtml(header))
98
+ .arg('content', htmlFragment);
99
+ const templateFile = template.file();
100
+ template
101
+ .handler()
102
+ .then(html => tryGenerateImage(resolve, reject, html, 640, templateFile))
103
+ .catch(reject);
104
+ });
105
+ }