@alemonjs/kook 2.1.2 → 2.1.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.
- package/README.md +5 -3
- package/lib/config.d.ts +1 -1
- package/lib/format.d.ts +3 -3
- package/lib/format.js +16 -2
- package/lib/index.js +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,8 +25,10 @@ kook:
|
|
|
25
25
|
master_id:
|
|
26
26
|
- 'yyy'
|
|
27
27
|
# 隐藏不支持的消息类型(可选,默认: false)
|
|
28
|
-
#
|
|
29
|
-
#
|
|
28
|
+
# 1:一级隐藏,不可读占位符([视频]、[音频]、[图片]、[附件]等)被置空,可读内容保留
|
|
29
|
+
# 2:二级隐藏,按钮仅显示指令数据(如 /挑战),链接仅显示 URL
|
|
30
|
+
# 3:三级隐藏,按钮和链接的 data 也不保留,完全隐藏
|
|
31
|
+
# 4:四级隐藏,不进行任何转换,降级数据直接丢弃
|
|
30
32
|
# 转换后内容为空时,将跳过发送并输出 info 日志
|
|
31
|
-
hideUnsupported:
|
|
33
|
+
hideUnsupported: 1
|
|
32
34
|
```
|
package/lib/config.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Options = {
|
|
|
3
3
|
token: string;
|
|
4
4
|
master_key?: string[];
|
|
5
5
|
master_id?: string[];
|
|
6
|
-
hideUnsupported?: boolean;
|
|
6
|
+
hideUnsupported?: boolean | number;
|
|
7
7
|
};
|
|
8
8
|
export declare const getKOOKConfig: () => Options;
|
|
9
9
|
export declare const getMaster: (UserId: string) => readonly [boolean, string];
|
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"], hideUnsupported?: boolean) => string;
|
|
3
|
-
export declare const markdownRawToKMarkdown: (raw: string, hideUnsupported?: boolean) => string;
|
|
4
|
-
export declare const dataEnumToKMarkdown: (item: DataEnums, hideUnsupported?: boolean) => string;
|
|
2
|
+
export declare const markdownToKMarkdown: (items: DataMarkDown["value"], hideUnsupported?: boolean | number) => string;
|
|
3
|
+
export declare const markdownRawToKMarkdown: (raw: string, hideUnsupported?: boolean | number) => string;
|
|
4
|
+
export declare const dataEnumToKMarkdown: (item: DataEnums, hideUnsupported?: boolean | number) => string;
|
package/lib/format.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const markdownToKMarkdown = (items, hideUnsupported) => {
|
|
2
|
+
if (Number(hideUnsupported) >= 4)
|
|
3
|
+
return '';
|
|
2
4
|
return items
|
|
3
5
|
.map(item => {
|
|
4
6
|
switch (item.type) {
|
|
@@ -17,7 +19,9 @@ const markdownToKMarkdown = (items, hideUnsupported) => {
|
|
|
17
19
|
return `~~${item.value}~~`;
|
|
18
20
|
case 'MD.link': {
|
|
19
21
|
const v = item.value;
|
|
20
|
-
|
|
22
|
+
if (Number(hideUnsupported) >= 3)
|
|
23
|
+
return '';
|
|
24
|
+
return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
|
|
21
25
|
}
|
|
22
26
|
case 'MD.image':
|
|
23
27
|
return hideUnsupported ? '' : '[图片]';
|
|
@@ -48,19 +52,29 @@ const markdownToKMarkdown = (items, hideUnsupported) => {
|
|
|
48
52
|
case 'MD.content':
|
|
49
53
|
return item.value;
|
|
50
54
|
case 'MD.button':
|
|
55
|
+
if (Number(hideUnsupported) >= 3)
|
|
56
|
+
return '';
|
|
57
|
+
if (Number(hideUnsupported) >= 2) {
|
|
58
|
+
return item.options?.data || String(item.value);
|
|
59
|
+
}
|
|
51
60
|
return hideUnsupported ? String(item.value) : `[${item.value}]`;
|
|
52
61
|
default:
|
|
53
62
|
return String(item?.value ?? '');
|
|
54
63
|
}
|
|
55
64
|
})
|
|
56
|
-
.join('')
|
|
65
|
+
.join('')
|
|
66
|
+
.trim();
|
|
57
67
|
};
|
|
58
68
|
const markdownRawToKMarkdown = (raw, hideUnsupported) => {
|
|
69
|
+
if (Number(hideUnsupported) >= 4)
|
|
70
|
+
return '';
|
|
59
71
|
let text = raw;
|
|
60
72
|
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
|
|
61
73
|
return text;
|
|
62
74
|
};
|
|
63
75
|
const dataEnumToKMarkdown = (item, hideUnsupported) => {
|
|
76
|
+
if (Number(hideUnsupported) >= 4)
|
|
77
|
+
return '';
|
|
64
78
|
switch (item.type) {
|
|
65
79
|
case 'Markdown':
|
|
66
80
|
return markdownToKMarkdown(item.value, hideUnsupported);
|
package/lib/index.js
CHANGED
|
@@ -329,12 +329,12 @@ const main = () => {
|
|
|
329
329
|
});
|
|
330
330
|
const formatKookContent = (val) => {
|
|
331
331
|
const nativeItems = val.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link');
|
|
332
|
-
const unsupportedItems = val.filter(item => item.type !== 'Mention'
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
332
|
+
const unsupportedItems = val.filter(item => item.type !== 'Mention' &&
|
|
333
|
+
item.type !== 'Text' &&
|
|
334
|
+
item.type !== 'Link' &&
|
|
335
|
+
item.type !== 'Image' &&
|
|
336
|
+
item.type !== 'ImageURL' &&
|
|
337
|
+
item.type !== 'ImageFile');
|
|
338
338
|
const nativeText = nativeItems
|
|
339
339
|
.map(item => {
|
|
340
340
|
if (item.type === 'Link') {
|
|
@@ -373,7 +373,7 @@ const main = () => {
|
|
|
373
373
|
return '';
|
|
374
374
|
})
|
|
375
375
|
.join('');
|
|
376
|
-
const hide = getKOOKConfig().hideUnsupported
|
|
376
|
+
const hide = getKOOKConfig().hideUnsupported;
|
|
377
377
|
const fallbackText = unsupportedItems.length > 0
|
|
378
378
|
? unsupportedItems
|
|
379
379
|
.map(item => dataEnumToKMarkdown(item, hide))
|
|
@@ -432,7 +432,7 @@ const main = () => {
|
|
|
432
432
|
const content = formatKookContent(val);
|
|
433
433
|
try {
|
|
434
434
|
const imageUrl = await uploadAndGetImageUrl(val);
|
|
435
|
-
if (getKOOKConfig().hideUnsupported
|
|
435
|
+
if (getKOOKConfig().hideUnsupported && !content && !imageUrl) {
|
|
436
436
|
logger.info('[kook] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
437
437
|
return [];
|
|
438
438
|
}
|
|
@@ -478,7 +478,7 @@ const main = () => {
|
|
|
478
478
|
const content = formatKookContent(val);
|
|
479
479
|
try {
|
|
480
480
|
const imageUrl = await uploadAndGetImageUrl(val);
|
|
481
|
-
if (getKOOKConfig().hideUnsupported
|
|
481
|
+
if (getKOOKConfig().hideUnsupported && !content && !imageUrl) {
|
|
482
482
|
logger.info('[kook] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
483
483
|
return [];
|
|
484
484
|
}
|