@alemonjs/qq-bot 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 CHANGED
@@ -46,4 +46,9 @@ qq-bot:
46
46
  # base_url_app_access_token: https://[your addr]
47
47
  # 启动md强制转换为text,特别是当没有md权限,但使用了md数据格式时
48
48
  markdownToText: true
49
+ # 隐藏不支持的消息类型(可选,默认: false)
50
+ # 开启后,转为文本时不可读内容(如 [视频]、[音频]、[图片]、[附件] 等占位符)将被置空
51
+ # 可读内容(如标题、按钮文本、链接等)仍会保留为纯文本
52
+ # 转换后内容为空时,将跳过发送并输出 info 日志
53
+ hideUnsupported: true
49
54
  ```
package/lib/config.d.ts CHANGED
@@ -4,6 +4,7 @@ export type Options = {
4
4
  master_key?: string[];
5
5
  master_id?: string[];
6
6
  markdownToText?: boolean;
7
+ hideUnsupported?: boolean;
7
8
  } & sdkOptions;
8
9
  export declare const getQQBotConfig: () => Options;
9
10
  export declare const getMaster: (UserId: string) => readonly [boolean, string];
package/lib/format.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DataEnums, DataMarkDown } from 'alemonjs';
2
- export declare const markdownToText: (items: DataMarkDown["value"]) => string;
2
+ export declare const markdownToText: (items: DataMarkDown["value"], hideUnsupported?: boolean) => string;
3
3
  export declare const buttonsToText: (rows: any[]) => string;
4
- export declare const markdownRawToText: (raw: string) => string;
5
- export declare const dataEnumToText: (item: DataEnums) => string;
4
+ export declare const markdownRawToText: (raw: string, hideUnsupported?: boolean) => string;
5
+ export declare const dataEnumToText: (item: DataEnums, hideUnsupported?: boolean) => string;
package/lib/format.js CHANGED
@@ -1,13 +1,13 @@
1
- const markdownToText = (items) => {
1
+ const markdownToText = (items, hideUnsupported) => {
2
2
  return items
3
3
  .map(item => {
4
4
  switch (item.type) {
5
5
  case 'MD.text':
6
6
  return item.value;
7
7
  case 'MD.title':
8
- return `【${item.value}】\n`;
8
+ return hideUnsupported ? `${item.value}\n` : `【${item.value}】\n`;
9
9
  case 'MD.subtitle':
10
- return `〖${item.value}〗\n`;
10
+ return hideUnsupported ? `${item.value}\n` : `〖${item.value}〗\n`;
11
11
  case 'MD.bold':
12
12
  case 'MD.italic':
13
13
  case 'MD.italicStar':
@@ -18,7 +18,7 @@ const markdownToText = (items) => {
18
18
  return `${v.text}( ${v.url} )`;
19
19
  }
20
20
  case 'MD.image':
21
- return '[图片]';
21
+ return hideUnsupported ? '' : '[图片]';
22
22
  case 'MD.list':
23
23
  return (item.value
24
24
  .map(li => {
@@ -31,7 +31,7 @@ const markdownToText = (items) => {
31
31
  case 'MD.blockquote':
32
32
  return `> ${item.value}\n`;
33
33
  case 'MD.divider':
34
- return '————————\n';
34
+ return hideUnsupported ? '' : '————————\n';
35
35
  case 'MD.newline':
36
36
  return '\n';
37
37
  case 'MD.code':
@@ -44,7 +44,7 @@ const markdownToText = (items) => {
44
44
  case 'MD.content':
45
45
  return item.value;
46
46
  case 'MD.button':
47
- return `[${item.value}]`;
47
+ return hideUnsupported ? String(item.value) : `[${item.value}]`;
48
48
  default:
49
49
  return String(item?.value ?? '');
50
50
  }
@@ -52,13 +52,11 @@ const markdownToText = (items) => {
52
52
  .join('');
53
53
  };
54
54
  const buttonsToText = (rows) => {
55
- return rows
56
- .map((row) => row.value.map((btn) => `[${btn.value}]`).join(' '))
57
- .join('\n');
55
+ return rows.map((row) => row.value.map((btn) => `[${btn.value}]`).join(' ')).join('\n');
58
56
  };
59
- const markdownRawToText = (raw) => {
57
+ const markdownRawToText = (raw, hideUnsupported) => {
60
58
  let text = raw;
61
- text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, '[图片]');
59
+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
62
60
  text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');
63
61
  text = text.replace(/^#{1,6}\s+/gm, '');
64
62
  text = text.replace(/(\*{3}|_{3})([^*_]+)\1/g, '$2');
@@ -71,21 +69,21 @@ const markdownRawToText = (raw) => {
71
69
  return match.replace(/```\w*\n?/g, '').trim();
72
70
  });
73
71
  text = text.replace(/^>\s+/gm, '');
74
- text = text.replace(/^[-*_]{3,}\s*$/gm, '————————');
72
+ text = text.replace(/^[-*_]{3,}\s*$/gm, hideUnsupported ? '' : '————————');
75
73
  text = text.replace(/^[\s]*[-*+]\s+/gm, '· ');
76
74
  text = text.replace(/^[\s]*(\d+)\.\s+/gm, '$1. ');
77
75
  return text.trim();
78
76
  };
79
- const dataEnumToText = (item) => {
77
+ const dataEnumToText = (item, hideUnsupported) => {
80
78
  switch (item.type) {
81
79
  case 'MarkdownOriginal':
82
- return markdownRawToText(String(item.value));
80
+ return markdownRawToText(String(item.value), hideUnsupported);
83
81
  case 'Attachment':
84
- return `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
82
+ return hideUnsupported ? '' : `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
85
83
  case 'Audio':
86
- return '[音频]';
84
+ return hideUnsupported ? '' : '[音频]';
87
85
  case 'Video':
88
- return '[视频]';
86
+ return hideUnsupported ? '' : '[视频]';
89
87
  default:
90
88
  return '';
91
89
  }
package/lib/sends.js CHANGED
@@ -165,10 +165,18 @@ const formatMention = (item, mode) => {
165
165
  };
166
166
  const extractContent = (val, mode) => {
167
167
  const nativeTypes = new Set([
168
- 'Mention', 'Text', 'Link',
169
- 'Image', 'ImageFile', 'ImageURL',
170
- 'Markdown', 'BT.group', 'ButtonTemplate',
171
- 'Ark.list', 'Ark.Card', 'Ark.BigCard'
168
+ 'Mention',
169
+ 'Text',
170
+ 'Link',
171
+ 'Image',
172
+ 'ImageFile',
173
+ 'ImageURL',
174
+ 'Markdown',
175
+ 'BT.group',
176
+ 'ButtonTemplate',
177
+ 'Ark.list',
178
+ 'Ark.Card',
179
+ 'Ark.BigCard'
172
180
  ]);
173
181
  const nativeText = val
174
182
  .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
@@ -185,9 +193,11 @@ const extractContent = (val, mode) => {
185
193
  return '';
186
194
  })
187
195
  .join('');
196
+ const config = getQQBotConfig();
197
+ const hide = config.hideUnsupported === true;
188
198
  const fallbackText = val
189
199
  .filter(item => !nativeTypes.has(item.type))
190
- .map(item => dataEnumToText(item))
200
+ .map(item => dataEnumToText(item, hide))
191
201
  .filter(Boolean)
192
202
  .join('\n');
193
203
  return [nativeText, fallbackText].filter(Boolean).join('\n');
@@ -336,6 +346,10 @@ const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMes
336
346
  });
337
347
  return [createResult(ResultCode.Ok, label, { id: res.id })];
338
348
  }
349
+ if (config.hideUnsupported === true && !content && !buildMdAndButtonsParams(val) && !buildArkParams(val)) {
350
+ logger.info('[qq-bot] hideUnsupported: 消息内容转换后为空,跳过发送');
351
+ return [];
352
+ }
339
353
  if (mdToText) {
340
354
  const textContent = flattenMdToText(content, val);
341
355
  if (textContent) {
@@ -399,6 +413,10 @@ const sendGuildMessage = async (content, val, baseParams, sendMessage, label) =>
399
413
  const res = await sendMessage({ content: imgContent, ...baseParams }, imageBuffer);
400
414
  return [createResult(ResultCode.Ok, label, { id: res?.id })];
401
415
  }
416
+ if (config.hideUnsupported === true && !content && !buildMdAndButtonsParams(val) && !buildArkParams(val)) {
417
+ logger.info('[qq-bot] hideUnsupported: 消息内容转换后为空,跳过发送');
418
+ return [];
419
+ }
402
420
  if (mdToText) {
403
421
  const textContent = flattenMdToText(content, val);
404
422
  if (textContent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",