yz-yuki-plugin 2.0.5-9 → 2.0.6-1
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/CHANGELOG.md +6 -0
- package/defaultConfig/bilibili/config.yaml +9 -0
- package/defaultConfig/weibo/config.yaml +3 -0
- package/lib/apps/bilibili.js +44 -37
- package/lib/index.js +1 -1
- package/lib/models/bilibili/bilibili.main.api.js +402 -0
- package/lib/models/bilibili/{bilibili.get.web.data.js → bilibili.main.get.web.data.js} +8 -7
- package/lib/models/bilibili/{bilibili.models.js → bilibili.main.models.js} +81 -250
- package/lib/models/bilibili/{bilibili.query.js → bilibili.main.query.js} +114 -92
- package/lib/models/bilibili/{bilibili.task.js → bilibili.main.task.js} +39 -15
- package/lib/models/bilibili/bilibili.risk.buid.fp.js +282 -0
- package/lib/models/bilibili/{bilibili.dm.img.js → bilibili.risk.dm.img.js} +2 -2
- package/lib/models/bilibili/{bilibili.ticket.js → bilibili.risk.ticket.js} +1 -1
- package/lib/models/bilibili/{bilibili.w_webid.js → bilibili.risk.w_webid.js} +4 -4
- package/lib/models/bilibili/bilibili.risk.wbi.js +102 -0
- package/lib/models/weibo/weibo.get.web.data.js +1 -2
- package/lib/models/weibo/weibo.query.js +19 -21
- package/lib/models/weibo/weibo.task.js +27 -11
- package/lib/utils/config.js +1 -1
- package/lib/utils/image.js +1 -1
- package/lib/utils/puppeteer.render.js +2 -0
- package/package.json +13 -11
- package/lib/models/bilibili/bilibili.api.js +0 -93
- package/lib/models/bilibili/bilibili.buid.fp.js +0 -77
- package/lib/models/bilibili/bilibili.wbi.js +0 -61
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
-
import {
|
|
3
|
-
import { readSyncCookie, cookieWithBiliTicket } from './bilibili.models.js';
|
|
4
|
-
import
|
|
2
|
+
import { Segment } from 'yunzaijs';
|
|
3
|
+
import { readSyncCookie, cookieWithBiliTicket } from './bilibili.main.models.js';
|
|
4
|
+
import BiliApi from './bilibili.main.api.js';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import lodash from 'lodash';
|
|
7
7
|
|
|
@@ -26,7 +26,7 @@ class BiliQuery {
|
|
|
26
26
|
desc = data?.modules?.module_dynamic?.major?.archive || {};
|
|
27
27
|
formatData.data.title = desc?.title;
|
|
28
28
|
formatData.data.content = this.parseRichTextNodes(desc?.desc);
|
|
29
|
-
formatData.data.url = this.formatUrl(desc?.jump_url);
|
|
29
|
+
formatData.data.url = this.formatUrl(desc?.jump_url) || '';
|
|
30
30
|
formatData.data.pubTime = author.pub_time;
|
|
31
31
|
formatData.data.pubTs = moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss');
|
|
32
32
|
formatData.data.category = '视频动态';
|
|
@@ -100,30 +100,36 @@ class BiliQuery {
|
|
|
100
100
|
formatData.data.title = desc?.title;
|
|
101
101
|
// 文章内容过长,则尝试获取全文
|
|
102
102
|
if (desc?.summary?.text?.length >= 480) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
formatData.data.content = this.
|
|
109
|
-
formatData.data.
|
|
103
|
+
const fullArticleContent = await this.getFullArticleContent(this.formatUrl(desc?.jump_url));
|
|
104
|
+
if (fullArticleContent) {
|
|
105
|
+
const { readInfo, articleType } = fullArticleContent;
|
|
106
|
+
// 文章链接类型为 cv(旧类型) 或者 opus(新类型)
|
|
107
|
+
if (articleType === 'cv') {
|
|
108
|
+
formatData.data.content = this.praseFullOldTypeArticleContent(readInfo?.content);
|
|
109
|
+
if (String(formatData.data.content).length < 100) {
|
|
110
|
+
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || '';
|
|
111
|
+
formatData.data.pics = pics;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
formatData.data.pics = [];
|
|
115
|
+
}
|
|
110
116
|
}
|
|
111
|
-
else {
|
|
112
|
-
|
|
117
|
+
else if (articleType === 'opus') {
|
|
118
|
+
const FullNewTypeArticleContent = this.praseFullNewTypeArticleContent(readInfo?.paragraphs);
|
|
119
|
+
if (FullNewTypeArticleContent) {
|
|
120
|
+
const { content, img } = FullNewTypeArticleContent;
|
|
121
|
+
formatData.data.content = content;
|
|
122
|
+
formatData.data.pics = img && img.length > 0 ? img : pics;
|
|
123
|
+
if (content && content.length < 100) {
|
|
124
|
+
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
113
127
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
formatData.data.content = content;
|
|
118
|
-
formatData.data.pics = img && img.length > 0 ? img : pics;
|
|
119
|
-
if (content && content.length < 100) {
|
|
120
|
-
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text);
|
|
128
|
+
else {
|
|
129
|
+
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || '';
|
|
130
|
+
formatData.data.pics = pics;
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
|
-
else {
|
|
124
|
-
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || '';
|
|
125
|
-
formatData.data.pics = pics;
|
|
126
|
-
}
|
|
127
133
|
}
|
|
128
134
|
else {
|
|
129
135
|
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || '';
|
|
@@ -146,7 +152,7 @@ class BiliQuery {
|
|
|
146
152
|
formatData.data.pics = pics;
|
|
147
153
|
formatData.data.content = '';
|
|
148
154
|
}
|
|
149
|
-
formatData.data.url = this.formatUrl(desc?.jump_url);
|
|
155
|
+
formatData.data.url = this.formatUrl(desc?.jump_url) || '';
|
|
150
156
|
formatData.data.pubTime = author.pub_time;
|
|
151
157
|
formatData.data.pubTs = moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss');
|
|
152
158
|
formatData.data.category = '文章动态';
|
|
@@ -208,7 +214,7 @@ class BiliQuery {
|
|
|
208
214
|
return `<span class="bili-rich-text-module topic" href="${jumpUrl}">${node?.text}</span>`;
|
|
209
215
|
case 'RICH_TEXT_NODE_TYPE_TEXT':
|
|
210
216
|
// 正文将 \n 替换为 <br> 以实现换行
|
|
211
|
-
return node
|
|
217
|
+
return node?.text?.replace(/\n/g, '<br>') || '';
|
|
212
218
|
case 'RICH_TEXT_NODE_TYPE_AT':
|
|
213
219
|
// 处理 @ 类型,使用官方的HTML标签写法
|
|
214
220
|
return `<span data-module="desc" data-type="at" data-oid="${node?.rid}" class="bili-rich-text-module at">${node?.text}</span>`;
|
|
@@ -272,7 +278,7 @@ class BiliQuery {
|
|
|
272
278
|
}
|
|
273
279
|
catch (err) {
|
|
274
280
|
logger?.error(`优纪插件:获取B站完整文章内容失败 [ ${postUrl} ] : ${err}`);
|
|
275
|
-
return null;
|
|
281
|
+
return { readInfo: null, articleType: null };
|
|
276
282
|
}
|
|
277
283
|
}
|
|
278
284
|
/**解析旧版完整文章内容 */
|
|
@@ -287,8 +293,19 @@ class BiliQuery {
|
|
|
287
293
|
});
|
|
288
294
|
return content;
|
|
289
295
|
}
|
|
290
|
-
|
|
291
|
-
*
|
|
296
|
+
/**
|
|
297
|
+
* 解析新版完整文章内容,将其转换为HTML格式的正文和图片数组。
|
|
298
|
+
* 该方法处理的是 MODULE_TYPE_CONTENT 类型的文章,文章内容由多个段落组成。
|
|
299
|
+
* 每个段落可能包含不同类型的内容,如正文、图片、链接、表情等。
|
|
300
|
+
*
|
|
301
|
+
* @param paragraphs - MODULE_TYPE_CONTENT 类型文章的段落数组,每个段落是一个对象。
|
|
302
|
+
* 每个段落对象包含一个 para_type 属性,用于标识段落类型(1表示正文,2表示图片)。
|
|
303
|
+
* 正文段落中可能包含多个 nodes,每个 node 表示一段文本或一个富文本元素。
|
|
304
|
+
* 图片段落中包含一个 pic 对象,其中 pics 是图片信息的数组。
|
|
305
|
+
* @returns 返回一个对象,包含两个属性:
|
|
306
|
+
* - content: string 类型,解析后的HTML格式的正文字符串。
|
|
307
|
+
* - img: array 类型,包含图片信息的对象数组,每个对象有 url、width 和 height 属性。
|
|
308
|
+
* 如果输入的 paragraphs 不是数组,则返回 null。
|
|
292
309
|
*/
|
|
293
310
|
static praseFullNewTypeArticleContent = (paragraphs) => {
|
|
294
311
|
if (Array.isArray(paragraphs)) {
|
|
@@ -300,54 +317,58 @@ class BiliQuery {
|
|
|
300
317
|
switch (item.para_type) {
|
|
301
318
|
case 1:
|
|
302
319
|
// 处理正文
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
jumpUrl
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
320
|
+
if (item.text?.nodes) {
|
|
321
|
+
content += item.text.nodes
|
|
322
|
+
.map((node) => {
|
|
323
|
+
let nodeType = node.type;
|
|
324
|
+
if (nodeType === 'TEXT_NODE_TYPE_RICH') {
|
|
325
|
+
let richType = node?.rich?.type;
|
|
326
|
+
switch (richType) {
|
|
327
|
+
case 'RICH_TEXT_NODE_TYPE_TOPIC':
|
|
328
|
+
// 确保链接以 https:// 开头
|
|
329
|
+
let jumpUrl = node?.rich?.jump_url;
|
|
330
|
+
if (jumpUrl && !jumpUrl.startsWith('http://') && !jumpUrl.startsWith('https://')) {
|
|
331
|
+
jumpUrl = `https://${jumpUrl}`;
|
|
332
|
+
}
|
|
333
|
+
return `<span class="bili-rich-text-module topic" href="${jumpUrl}">${node?.rich?.text}</span>`;
|
|
334
|
+
case 'RICH_TEXT_NODE_TYPE_TEXT':
|
|
335
|
+
// 正文将 \n 替换为 <br> 以实现换行
|
|
336
|
+
return node?.rich?.text.replace(/\n/g, '<br>');
|
|
337
|
+
case 'RICH_TEXT_NODE_TYPE_AT':
|
|
338
|
+
// 处理 @ 类型,使用官方的HTML标签写法
|
|
339
|
+
return `<span data-module="desc" data-type="at" data-oid="${node?.rich?.rid}" class="bili-rich-text-module at">${node?.rich?.text}</span>`;
|
|
340
|
+
case 'RICH_TEXT_NODE_TYPE_LOTTERY':
|
|
341
|
+
// 处理互动抽奖类型,使用官方的HTML标签写法
|
|
342
|
+
return `<span data-module="desc" data-type="lottery" data-oid="${node?.rich?.rid}" class="bili-rich-text-module lottery">${node?.rich?.text}</span>`;
|
|
343
|
+
case 'RICH_TEXT_NODE_TYPE_WEB':
|
|
344
|
+
// 处理 RICH_TEXT_NODE_TYPE_WEB 类型,直接拼接 text 属性
|
|
345
|
+
return node?.rich?.text;
|
|
346
|
+
case 'RICH_TEXT_NODE_TYPE_EMOJI':
|
|
347
|
+
// 处理表情类型,使用 img 标签显示表情
|
|
348
|
+
const emoji = node?.rich?.emoji;
|
|
349
|
+
return `<img src="${emoji?.icon_url}" alt="${emoji?.text}" title="${emoji?.text}" style="vertical-align: middle; width: ${emoji?.size}em; height: ${emoji?.size}em;">`;
|
|
350
|
+
case 'RICH_TEXT_NODE_TYPE_GOODS':
|
|
351
|
+
// 处理商品推广类型,使用官方的HTML标签写法
|
|
352
|
+
const goods_url = node?.rich?.jump_url;
|
|
353
|
+
return `<span data-module="desc" data-type="goods" data-url="${goods_url}" data-oid="${node?.rich?.rid}" class="bili-rich-text-module goods ${node?.rich?.icon_name}">​${node?.rich?.text}</span>`;
|
|
354
|
+
default:
|
|
355
|
+
return node;
|
|
356
|
+
}
|
|
338
357
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
358
|
+
else if (nodeType === 'TEXT_NODE_TYPE_WORD') {
|
|
359
|
+
return `${node?.word?.words}<br>`;
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
.join('');
|
|
363
|
+
}
|
|
345
364
|
break;
|
|
346
365
|
case 2:
|
|
347
366
|
// 处理图片
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
367
|
+
if (item?.pic?.pics) {
|
|
368
|
+
img = img.concat(item?.pic?.pics.map((item) => {
|
|
369
|
+
return { url: item?.url, width: item?.width, height: item?.height };
|
|
370
|
+
}) || []);
|
|
371
|
+
}
|
|
351
372
|
break;
|
|
352
373
|
}
|
|
353
374
|
});
|
|
@@ -372,7 +393,7 @@ class BiliQuery {
|
|
|
372
393
|
*/
|
|
373
394
|
static async formatTextDynamicData(upName, data, isForward, setData) {
|
|
374
395
|
const BiliDrawDynamicLinkUrl = 'https://m.bilibili.com/dynamic/';
|
|
375
|
-
let desc, msg, pics, author, majorType, content, dynamicTitle;
|
|
396
|
+
let desc, msg = [], pics = [], author, majorType, content, dynamicTitle;
|
|
376
397
|
let title = `B站【${upName}】动态推送:\n`;
|
|
377
398
|
switch (data.type) {
|
|
378
399
|
case 'DYNAMIC_TYPE_AV':
|
|
@@ -388,10 +409,10 @@ class BiliQuery {
|
|
|
388
409
|
`标题:${desc.title}\n`,
|
|
389
410
|
`${desc.desc}\n`,
|
|
390
411
|
`链接:${this.formatUrl(desc.jump_url)}\n`,
|
|
391
|
-
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}
|
|
392
|
-
Segment.image(desc?.cover)
|
|
412
|
+
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
|
|
393
413
|
];
|
|
394
|
-
|
|
414
|
+
pics = [Segment.image(desc?.cover)];
|
|
415
|
+
return { msg, pics };
|
|
395
416
|
case 'DYNAMIC_TYPE_WORD':
|
|
396
417
|
// 处理文字动态
|
|
397
418
|
author = data?.modules?.module_author;
|
|
@@ -421,7 +442,7 @@ class BiliQuery {
|
|
|
421
442
|
`链接:${BiliDrawDynamicLinkUrl}${data.id_str}\n`,
|
|
422
443
|
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
|
|
423
444
|
];
|
|
424
|
-
return msg;
|
|
445
|
+
return { msg, pics };
|
|
425
446
|
case 'DYNAMIC_TYPE_DRAW':
|
|
426
447
|
// 处理图文动态
|
|
427
448
|
author = data?.modules?.module_author;
|
|
@@ -465,10 +486,9 @@ class BiliQuery {
|
|
|
465
486
|
`-----------------------------\n`,
|
|
466
487
|
`${this.dynamicContentLimit(content, setData)}\n`,
|
|
467
488
|
`链接:${BiliDrawDynamicLinkUrl}${data.id_str}\n`,
|
|
468
|
-
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}
|
|
469
|
-
...pics
|
|
489
|
+
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
|
|
470
490
|
];
|
|
471
|
-
return msg;
|
|
491
|
+
return { msg, pics };
|
|
472
492
|
case 'DYNAMIC_TYPE_ARTICLE':
|
|
473
493
|
// 处理文章动态
|
|
474
494
|
author = data?.modules?.module_author;
|
|
@@ -509,10 +529,9 @@ class BiliQuery {
|
|
|
509
529
|
`-----------------------------\n`,
|
|
510
530
|
`标题:${dynamicTitle}\n`,
|
|
511
531
|
`链接:${this.formatUrl(desc.jump_url)}\n`,
|
|
512
|
-
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}
|
|
513
|
-
...pics
|
|
532
|
+
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
|
|
514
533
|
];
|
|
515
|
-
return msg;
|
|
534
|
+
return { msg, pics };
|
|
516
535
|
case 'DYNAMIC_TYPE_FORWARD':
|
|
517
536
|
// 处理转发动态
|
|
518
537
|
author = data?.modules?.module_author;
|
|
@@ -524,11 +543,13 @@ class BiliQuery {
|
|
|
524
543
|
return;
|
|
525
544
|
isForward = true;
|
|
526
545
|
let orig = await this.formatTextDynamicData(upName, data.orig, isForward, setData);
|
|
527
|
-
|
|
528
|
-
|
|
546
|
+
let origContent = [];
|
|
547
|
+
if (orig && typeof orig === 'object') {
|
|
548
|
+
origContent = orig.msg.slice(2);
|
|
549
|
+
pics = orig.pics;
|
|
529
550
|
}
|
|
530
551
|
else {
|
|
531
|
-
return
|
|
552
|
+
return 'continue';
|
|
532
553
|
}
|
|
533
554
|
title = `B站【${upName}】转发动态推送:\n`;
|
|
534
555
|
msg = [
|
|
@@ -538,9 +559,9 @@ class BiliQuery {
|
|
|
538
559
|
`链接:${BiliDrawDynamicLinkUrl}${data.id_str}\n`,
|
|
539
560
|
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}\n`,
|
|
540
561
|
'\n---以下为转发内容---\n',
|
|
541
|
-
...
|
|
562
|
+
...origContent
|
|
542
563
|
];
|
|
543
|
-
return msg;
|
|
564
|
+
return { msg, pics };
|
|
544
565
|
case 'DYNAMIC_TYPE_LIVE_RCMD':
|
|
545
566
|
// 处理直播动态
|
|
546
567
|
desc = data?.modules?.module_dynamic?.major?.live_rcmd?.content;
|
|
@@ -551,11 +572,12 @@ class BiliQuery {
|
|
|
551
572
|
if (!desc)
|
|
552
573
|
return;
|
|
553
574
|
title = `B站【${upName}】直播动态推送:\n`;
|
|
554
|
-
msg = [title, `-----------------------------\n`, `标题:${desc.title}\n`, `链接:https:${desc.link}
|
|
555
|
-
|
|
575
|
+
msg = [title, `-----------------------------\n`, `标题:${desc.title}\n`, `链接:https:${desc.link}`];
|
|
576
|
+
pics = [Segment.image(desc.cover)];
|
|
577
|
+
return { msg, pics };
|
|
556
578
|
default:
|
|
557
579
|
// 处理未定义的动态类型
|
|
558
|
-
|
|
580
|
+
global?.logger?.mark(`未处理的B站推送【${upName}】:${data.type}`);
|
|
559
581
|
return 'continue';
|
|
560
582
|
}
|
|
561
583
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import QRCode from 'qrcode';
|
|
2
|
-
import { Redis,
|
|
2
|
+
import { Redis, Segment, Bot } from 'yunzaijs';
|
|
3
3
|
import Config from '../../utils/config.js';
|
|
4
4
|
import { renderPage } from '../../utils/image.js';
|
|
5
|
-
import { BiliGetWebData } from './bilibili.get.web.data.js';
|
|
6
|
-
import { readSyncCookie, postGateway } from './bilibili.models.js';
|
|
7
|
-
import { BiliQuery } from './bilibili.query.js';
|
|
5
|
+
import { BiliGetWebData } from './bilibili.main.get.web.data.js';
|
|
6
|
+
import { readSyncCookie, postGateway } from './bilibili.main.models.js';
|
|
7
|
+
import { BiliQuery } from './bilibili.main.query.js';
|
|
8
8
|
|
|
9
9
|
class BiliTask {
|
|
10
10
|
taskName;
|
|
@@ -59,6 +59,8 @@ class BiliTask {
|
|
|
59
59
|
uidMap.set(chatType, new Map());
|
|
60
60
|
}
|
|
61
61
|
const chatTypeMap = uidMap.get(chatType); // 建立当前 chatType (group 或 private) 的 uid 映射
|
|
62
|
+
if (chatTypeMap === undefined)
|
|
63
|
+
continue; // 如果 chatTypeMap 未定义,跳过此次循环
|
|
62
64
|
for (let chatId in biliPushData[chatType]) {
|
|
63
65
|
const subUpsOfChat = Array.prototype.slice.call(biliPushData[chatType][chatId] || []);
|
|
64
66
|
for (let subInfoOfup of subUpsOfChat) {
|
|
@@ -148,10 +150,18 @@ class BiliTask {
|
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
|
-
|
|
153
|
+
/**
|
|
154
|
+
* 发送动态消息
|
|
155
|
+
* @param chatId 聊天 ID
|
|
156
|
+
* @param bot_id 机器人 ID
|
|
157
|
+
* @param upName 用户名
|
|
158
|
+
* @param pushDynamicData 推送动态数据
|
|
159
|
+
* @param biliConfigData 哔哩配置数据
|
|
160
|
+
* @param chatType 聊天类型
|
|
161
|
+
*/
|
|
152
162
|
async sendDynamic(chatId, bot_id, upName, pushDynamicData, biliConfigData, chatType) {
|
|
153
163
|
const id_str = pushDynamicData.id_str;
|
|
154
|
-
let sended, markKey;
|
|
164
|
+
let sended = null, markKey = '';
|
|
155
165
|
if (chatType === 'group') {
|
|
156
166
|
markKey = this.groupKey;
|
|
157
167
|
sended = await Redis.get(`${markKey}${chatId}:${id_str}`);
|
|
@@ -191,8 +201,8 @@ class BiliTask {
|
|
|
191
201
|
let imgs = await this.renderDynamicCard(uid, renderData, ScreenshotOptionsData);
|
|
192
202
|
if (!imgs)
|
|
193
203
|
return;
|
|
194
|
-
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 *
|
|
195
|
-
|
|
204
|
+
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 * 72 }); // 设置已发送标记
|
|
205
|
+
logger?.mark('优纪插件:B站动态执行推送');
|
|
196
206
|
for (let i = 0; i < imgs.length; i++) {
|
|
197
207
|
const image = imgs[i];
|
|
198
208
|
await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
|
|
@@ -202,18 +212,32 @@ class BiliTask {
|
|
|
202
212
|
}
|
|
203
213
|
else {
|
|
204
214
|
const dynamicMsg = await BiliQuery.formatTextDynamicData(upName, pushDynamicData, false, biliConfigData); // 构建图文动态消息
|
|
205
|
-
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 *
|
|
206
|
-
if (dynamicMsg
|
|
215
|
+
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 * 72 }); // 设置已发送标记
|
|
216
|
+
if (dynamicMsg === undefined || dynamicMsg === 'continue') {
|
|
207
217
|
return 'return'; // 如果动态消息构建失败,则直接返回
|
|
208
218
|
}
|
|
209
219
|
if (biliConfigData.banWords.length > 0) {
|
|
210
220
|
const banWords = new RegExp(biliConfigData.banWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式
|
|
211
|
-
if (banWords.test(dynamicMsg.join(''))) {
|
|
221
|
+
if (banWords.test(dynamicMsg.msg.join(''))) {
|
|
212
222
|
return 'return'; // 如果动态消息包含屏蔽关键字,则直接返回
|
|
213
223
|
}
|
|
214
224
|
}
|
|
215
|
-
|
|
216
|
-
|
|
225
|
+
let mergeTextPic = !!biliConfigData.mergeTextPic === false ? false : true; // 是否合并文本和图片,默认为 true
|
|
226
|
+
if (mergeTextPic) {
|
|
227
|
+
const mergeMsg = [...dynamicMsg.msg, ...dynamicMsg.pics];
|
|
228
|
+
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
|
|
232
|
+
const pics = dynamicMsg.pics;
|
|
233
|
+
if (pics && pics.length > 0) {
|
|
234
|
+
for (let i = 0; i < pics.length; i++) {
|
|
235
|
+
await this.sendMessage(chatId, bot_id, chatType, pics[i]);
|
|
236
|
+
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
240
|
+
}
|
|
217
241
|
}
|
|
218
242
|
}
|
|
219
243
|
/**
|
|
@@ -305,7 +329,7 @@ class BiliTask {
|
|
|
305
329
|
?.pickGroup(String(chatId))
|
|
306
330
|
.sendMsg(message) // 发送群聊
|
|
307
331
|
.catch((error) => {
|
|
308
|
-
|
|
332
|
+
global?.logger?.error(`群组[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
309
333
|
});
|
|
310
334
|
}
|
|
311
335
|
else if (chatType === 'private') {
|
|
@@ -313,7 +337,7 @@ class BiliTask {
|
|
|
313
337
|
?.pickFriend(String(chatId))
|
|
314
338
|
.sendMsg(message)
|
|
315
339
|
.catch((error) => {
|
|
316
|
-
|
|
340
|
+
global?.logger?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
317
341
|
}); // 发送好友私聊
|
|
318
342
|
}
|
|
319
343
|
}
|