@alemonjs/kook 2.1.1 → 2.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 +5 -0
- package/lib/config.d.ts +1 -0
- package/lib/format.d.ts +3 -3
- package/lib/format.js +13 -15
- package/lib/index.js +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/config.d.ts
CHANGED
package/lib/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DataEnums, DataMarkDown } from 'alemonjs';
|
|
2
|
-
export declare const markdownToKMarkdown: (items: DataMarkDown["value"]) => string;
|
|
3
|
-
export declare const markdownRawToKMarkdown: (raw: string) => string;
|
|
4
|
-
export declare const dataEnumToKMarkdown: (item: DataEnums) => string;
|
|
2
|
+
export declare const markdownToKMarkdown: (items: DataMarkDown["value"], hideUnsupported?: boolean) => string;
|
|
3
|
+
export declare const markdownRawToKMarkdown: (raw: string, hideUnsupported?: boolean) => string;
|
|
4
|
+
export declare const dataEnumToKMarkdown: (item: DataEnums, hideUnsupported?: boolean) => string;
|
package/lib/format.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const markdownToKMarkdown = (items) => {
|
|
1
|
+
const markdownToKMarkdown = (items, hideUnsupported) => {
|
|
2
2
|
return items
|
|
3
3
|
.map(item => {
|
|
4
4
|
switch (item.type) {
|
|
@@ -20,7 +20,7 @@ const markdownToKMarkdown = (items) => {
|
|
|
20
20
|
return `[${v.text}](${v.url})`;
|
|
21
21
|
}
|
|
22
22
|
case 'MD.image':
|
|
23
|
-
return '[图片]';
|
|
23
|
+
return hideUnsupported ? '' : '[图片]';
|
|
24
24
|
case 'MD.list':
|
|
25
25
|
return (item.value
|
|
26
26
|
.map(li => {
|
|
@@ -33,7 +33,7 @@ const markdownToKMarkdown = (items) => {
|
|
|
33
33
|
case 'MD.blockquote':
|
|
34
34
|
return `> ${item.value}\n`;
|
|
35
35
|
case 'MD.divider':
|
|
36
|
-
return '---\n';
|
|
36
|
+
return hideUnsupported ? '' : '---\n';
|
|
37
37
|
case 'MD.newline':
|
|
38
38
|
return '\n';
|
|
39
39
|
case 'MD.code': {
|
|
@@ -48,35 +48,33 @@ const markdownToKMarkdown = (items) => {
|
|
|
48
48
|
case 'MD.content':
|
|
49
49
|
return item.value;
|
|
50
50
|
case 'MD.button':
|
|
51
|
-
return `[${item.value}]`;
|
|
51
|
+
return hideUnsupported ? String(item.value) : `[${item.value}]`;
|
|
52
52
|
default:
|
|
53
53
|
return String(item?.value ?? '');
|
|
54
54
|
}
|
|
55
55
|
})
|
|
56
56
|
.join('');
|
|
57
57
|
};
|
|
58
|
-
const markdownRawToKMarkdown = (raw) => {
|
|
58
|
+
const markdownRawToKMarkdown = (raw, hideUnsupported) => {
|
|
59
59
|
let text = raw;
|
|
60
|
-
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, '[图片]');
|
|
60
|
+
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
|
|
61
61
|
return text;
|
|
62
62
|
};
|
|
63
|
-
const dataEnumToKMarkdown = (item) => {
|
|
63
|
+
const dataEnumToKMarkdown = (item, hideUnsupported) => {
|
|
64
64
|
switch (item.type) {
|
|
65
65
|
case 'Markdown':
|
|
66
|
-
return markdownToKMarkdown(item.value);
|
|
66
|
+
return markdownToKMarkdown(item.value, hideUnsupported);
|
|
67
67
|
case 'MarkdownOriginal':
|
|
68
|
-
return markdownRawToKMarkdown(String(item.value));
|
|
68
|
+
return markdownRawToKMarkdown(String(item.value), hideUnsupported);
|
|
69
69
|
case 'BT.group':
|
|
70
70
|
case 'ButtonGroup':
|
|
71
|
-
return item.value
|
|
72
|
-
.map((row) => row.value.map((btn) => `[${btn.value}]`).join(' '))
|
|
73
|
-
.join('\n');
|
|
71
|
+
return hideUnsupported ? '' : item.value.map((row) => row.value.map((btn) => `[${btn.value}]`).join(' ')).join('\n');
|
|
74
72
|
case 'Attachment':
|
|
75
|
-
return `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
|
|
73
|
+
return hideUnsupported ? '' : `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
|
|
76
74
|
case 'Audio':
|
|
77
|
-
return '[音频]';
|
|
75
|
+
return hideUnsupported ? '' : '[音频]';
|
|
78
76
|
case 'Video':
|
|
79
|
-
return '[视频]';
|
|
77
|
+
return hideUnsupported ? '' : '[视频]';
|
|
80
78
|
default:
|
|
81
79
|
return '';
|
|
82
80
|
}
|
package/lib/index.js
CHANGED
|
@@ -373,8 +373,12 @@ const main = () => {
|
|
|
373
373
|
return '';
|
|
374
374
|
})
|
|
375
375
|
.join('');
|
|
376
|
+
const hide = getKOOKConfig().hideUnsupported === true;
|
|
376
377
|
const fallbackText = unsupportedItems.length > 0
|
|
377
|
-
? unsupportedItems
|
|
378
|
+
? unsupportedItems
|
|
379
|
+
.map(item => dataEnumToKMarkdown(item, hide))
|
|
380
|
+
.filter(Boolean)
|
|
381
|
+
.join('')
|
|
378
382
|
: '';
|
|
379
383
|
return [nativeText, fallbackText].filter(Boolean).join('');
|
|
380
384
|
};
|
|
@@ -428,6 +432,10 @@ const main = () => {
|
|
|
428
432
|
const content = formatKookContent(val);
|
|
429
433
|
try {
|
|
430
434
|
const imageUrl = await uploadAndGetImageUrl(val);
|
|
435
|
+
if (getKOOKConfig().hideUnsupported === true && !content && !imageUrl) {
|
|
436
|
+
logger.info('[kook] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
437
|
+
return [];
|
|
438
|
+
}
|
|
431
439
|
if (imageUrl && content) {
|
|
432
440
|
const imgRes = await client.createMessage({
|
|
433
441
|
type: 2,
|
|
@@ -470,6 +478,10 @@ const main = () => {
|
|
|
470
478
|
const content = formatKookContent(val);
|
|
471
479
|
try {
|
|
472
480
|
const imageUrl = await uploadAndGetImageUrl(val);
|
|
481
|
+
if (getKOOKConfig().hideUnsupported === true && !content && !imageUrl) {
|
|
482
|
+
logger.info('[kook] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
483
|
+
return [];
|
|
484
|
+
}
|
|
473
485
|
if (imageUrl && content) {
|
|
474
486
|
const imgRes = await client.createDirectMessage({
|
|
475
487
|
type: 2,
|