@alemonjs/kook 2.1.2 → 2.1.4

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 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: true
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
- return `[${v.text}](${v.url})`;
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,6 +52,11 @@ 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 ?? '');
@@ -56,11 +65,15 @@ const markdownToKMarkdown = (items, hideUnsupported) => {
56
65
  .join('');
57
66
  };
58
67
  const markdownRawToKMarkdown = (raw, hideUnsupported) => {
68
+ if (Number(hideUnsupported) >= 4)
69
+ return '';
59
70
  let text = raw;
60
71
  text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
61
72
  return text;
62
73
  };
63
74
  const dataEnumToKMarkdown = (item, hideUnsupported) => {
75
+ if (Number(hideUnsupported) >= 4)
76
+ return '';
64
77
  switch (item.type) {
65
78
  case 'Markdown':
66
79
  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
- && item.type !== 'Text'
334
- && item.type !== 'Link'
335
- && item.type !== 'Image'
336
- && item.type !== 'ImageURL'
337
- && item.type !== 'ImageFile');
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,14 +373,14 @@ const main = () => {
373
373
  return '';
374
374
  })
375
375
  .join('');
376
- const hide = getKOOKConfig().hideUnsupported === true;
376
+ const hide = getKOOKConfig().hideUnsupported;
377
377
  const fallbackText = unsupportedItems.length > 0
378
378
  ? unsupportedItems
379
379
  .map(item => dataEnumToKMarkdown(item, hide))
380
380
  .filter(Boolean)
381
381
  .join('')
382
382
  : '';
383
- return [nativeText, fallbackText].filter(Boolean).join('');
383
+ return [nativeText, fallbackText].filter(Boolean).join('').replace(/^[^\S\n\r]+|[^\S\n\r]+$/g, '');
384
384
  };
385
385
  const resolveImageBuffer = async (val) => {
386
386
  const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
@@ -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 === true && !content && !imageUrl) {
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 === true && !content && !imageUrl) {
481
+ if (getKOOKConfig().hideUnsupported && !content && !imageUrl) {
482
482
  logger.info('[kook] hideUnsupported: 消息内容转换后为空,跳过发送');
483
483
  return [];
484
484
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/kook",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "kook platform connection",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",