yz-yuki-plugin 2.0.7-5 → 2.0.7-7
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/lib/models/bilibili/bilibili.main.get.web.data.js +1 -5
- package/lib/models/bilibili/bilibili.main.task.js +23 -19
- package/lib/models/bilibili/bilibili.risk.dm.img.js +4 -4
- package/lib/models/weibo/weibo.main.task.js +23 -19
- package/package.json +1 -1
- package/lib/models/bilibili/bilibili.risk.w_webid.js +0 -46
|
@@ -4,7 +4,6 @@ import BiliApi from './bilibili.main.api.js';
|
|
|
4
4
|
import { readSyncCookie, cookieWithBiliTicket, readSavedCookieItems, readSavedCookieOtherItems } from './bilibili.main.models.js';
|
|
5
5
|
import { getWbiSign } from './bilibili.risk.wbi.js';
|
|
6
6
|
import { getDmImg } from './bilibili.risk.dm.img.js';
|
|
7
|
-
import { getWebId } from './bilibili.risk.w_webid.js';
|
|
8
7
|
|
|
9
8
|
class BilibiliWebDataFetcher {
|
|
10
9
|
e;
|
|
@@ -52,20 +51,17 @@ class BilibiliWebDataFetcher {
|
|
|
52
51
|
let { cookie } = await readSyncCookie();
|
|
53
52
|
cookie = await cookieWithBiliTicket(cookie);
|
|
54
53
|
const dmImg = await getDmImg();
|
|
55
|
-
const w_webid = await getWebId(uid);
|
|
56
54
|
const data = {
|
|
57
55
|
mid: uid,
|
|
58
56
|
token: '',
|
|
59
57
|
platform: 'web',
|
|
60
58
|
web_location: 1550101,
|
|
61
|
-
...dmImg
|
|
62
|
-
w_webid: w_webid
|
|
59
|
+
...dmImg
|
|
63
60
|
};
|
|
64
61
|
let signCookie = (await readSavedCookieItems(cookie, ['SESSDATA'], false)) || (await readSavedCookieOtherItems(cookie, ['SESSDATA']));
|
|
65
62
|
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
|
|
66
63
|
const params = {
|
|
67
64
|
...data,
|
|
68
|
-
w_webid: w_webid,
|
|
69
65
|
w_rid: w_rid,
|
|
70
66
|
wts: time_stamp
|
|
71
67
|
};
|
|
@@ -421,15 +421,22 @@ class BiliTask {
|
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
if (sendMode === 'SINGLE') {
|
|
424
|
+
let allSent = true;
|
|
424
425
|
for (let i = 0; i < messages.length; i++) {
|
|
425
|
-
await this.sendMessageApi(chatId, bot_id, chatType, messages[i])
|
|
426
|
+
if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
|
|
427
|
+
allSent = false;
|
|
428
|
+
break; // 如果有任何一条消息发送失败,停止发送后续消息
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (allSent) {
|
|
432
|
+
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
433
|
+
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
426
434
|
}
|
|
427
|
-
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
428
|
-
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
429
435
|
}
|
|
430
436
|
else if (sendMode === 'MERGE') {
|
|
431
|
-
await this.sendMessageApi(chatId, bot_id, chatType, messages)
|
|
432
|
-
|
|
437
|
+
if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
|
|
438
|
+
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
439
|
+
}
|
|
433
440
|
}
|
|
434
441
|
}
|
|
435
442
|
}
|
|
@@ -445,21 +452,18 @@ class BiliTask {
|
|
|
445
452
|
* @param message 消息内容
|
|
446
453
|
*/
|
|
447
454
|
async sendMessageApi(chatId, bot_id, chatType, message) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
?.pickGroup(String(chatId))
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
+
try {
|
|
456
|
+
if (chatType === 'group') {
|
|
457
|
+
await (Bot[bot_id] ?? Bot)?.pickGroup(String(chatId)).sendMsg(message); // 发送群聊
|
|
458
|
+
}
|
|
459
|
+
else if (chatType === 'private') {
|
|
460
|
+
await (Bot[bot_id] ?? Bot)?.pickFriend(String(chatId)).sendMsg(message); // 发送好友私聊
|
|
461
|
+
}
|
|
462
|
+
return true; // 发送成功
|
|
455
463
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
.sendMsg(message)
|
|
460
|
-
.catch((error) => {
|
|
461
|
-
global?.logger?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
462
|
-
}); // 发送好友私聊
|
|
464
|
+
catch (error) {
|
|
465
|
+
global?.logger?.error(`${chatType === 'group' ? '群聊' : '私聊'} ${chatId} 消息发送失败:${JSON.stringify(error)}`);
|
|
466
|
+
return false; // 发送失败
|
|
463
467
|
}
|
|
464
468
|
}
|
|
465
469
|
/**
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**获取dm参数 */
|
|
2
2
|
async function getDmImg() {
|
|
3
|
-
const dm_img_list = []
|
|
3
|
+
const dm_img_list = `[]`;
|
|
4
4
|
//Buffer.from("WebGL 1", 'utf-8').toString("base64") //webgl version的值 WebGL 1 的base64 编码
|
|
5
5
|
const dm_img_str = 'V2ViR0wgMS';
|
|
6
6
|
//webgl unmasked renderer的值拼接webgl unmasked vendor的值的base64编码
|
|
7
7
|
const dm_cover_img_str = 'QU5HTEUgKEludGVsLCBJbnRlbChSKSBIRCBHcmFwaGljcyBEaXJlY3QzRDExIHZzXzVfMCBwc181XzApLCBvciBzaW1pbGFyR29vZ2xlIEluYy4gKEludGVsKQ';
|
|
8
|
-
const dm_img_inter = {
|
|
8
|
+
const dm_img_inter = `{ds:[],wh:[0,0,0],of:[0,0,0]}`;
|
|
9
9
|
return {
|
|
10
|
-
dm_img_list:
|
|
10
|
+
dm_img_list: dm_img_list,
|
|
11
11
|
dm_img_str: dm_img_str,
|
|
12
12
|
dm_cover_img_str: dm_cover_img_str,
|
|
13
|
-
dm_img_inter:
|
|
13
|
+
dm_img_inter: dm_img_inter
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -368,15 +368,22 @@ class WeiboTask {
|
|
|
368
368
|
LogMark.add('1');
|
|
369
369
|
}
|
|
370
370
|
if (sendMode === 'SINGLE') {
|
|
371
|
+
let allSent = true;
|
|
371
372
|
for (let i = 0; i < messages.length; i++) {
|
|
372
|
-
await this.sendMessageApi(chatId, bot_id, chatType, messages[i])
|
|
373
|
+
if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
|
|
374
|
+
allSent = false;
|
|
375
|
+
break; // 如果有任何一条消息发送失败,停止发送后续消息
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (allSent) {
|
|
379
|
+
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
380
|
+
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
373
381
|
}
|
|
374
|
-
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
375
|
-
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
376
382
|
}
|
|
377
383
|
else if (sendMode === 'MERGE') {
|
|
378
|
-
await this.sendMessageApi(chatId, bot_id, chatType, messages)
|
|
379
|
-
|
|
384
|
+
if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
|
|
385
|
+
await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
|
|
386
|
+
}
|
|
380
387
|
}
|
|
381
388
|
}
|
|
382
389
|
}
|
|
@@ -392,21 +399,18 @@ class WeiboTask {
|
|
|
392
399
|
* @param message 消息内容
|
|
393
400
|
*/
|
|
394
401
|
async sendMessageApi(chatId, bot_id, chatType, message) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
?.pickGroup(String(chatId))
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
+
try {
|
|
403
|
+
if (chatType === 'group') {
|
|
404
|
+
await (Bot[bot_id] ?? Bot)?.pickGroup(String(chatId)).sendMsg(message); // 发送群聊
|
|
405
|
+
}
|
|
406
|
+
else if (chatType === 'private') {
|
|
407
|
+
await (Bot[bot_id] ?? Bot)?.pickFriend(String(chatId)).sendMsg(message); // 发送好友私聊
|
|
408
|
+
}
|
|
409
|
+
return true; // 发送成功
|
|
402
410
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
.sendMsg(message)
|
|
407
|
-
.catch(error => {
|
|
408
|
-
global?.logger?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
409
|
-
}); // 发送好友私聊
|
|
411
|
+
catch (error) {
|
|
412
|
+
global?.logger?.error(`${chatType === 'group' ? '群聊' : '私聊'} ${chatId} 消息发送失败:${JSON.stringify(error)}`);
|
|
413
|
+
return false; // 发送失败
|
|
410
414
|
}
|
|
411
415
|
}
|
|
412
416
|
/**
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import lodash from 'lodash';
|
|
3
|
-
import { Redis } from 'yunzaijs';
|
|
4
|
-
import BiliApi from './bilibili.main.api.js';
|
|
5
|
-
import { readSyncCookie, cookieWithBiliTicket } from './bilibili.main.models.js';
|
|
6
|
-
|
|
7
|
-
async function getWebId(uid) {
|
|
8
|
-
const w_webid_key = 'Yz:yuki:bili:w_webid';
|
|
9
|
-
const w_webid = await Redis.get(w_webid_key);
|
|
10
|
-
const keyTTL = await Redis.ttl(w_webid_key);
|
|
11
|
-
if (w_webid && keyTTL < 259200) {
|
|
12
|
-
return String(w_webid);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const url = `https://space.bilibili.com/${uid ? uid : 401742377}/dynamic`;
|
|
16
|
-
let { cookie } = await readSyncCookie();
|
|
17
|
-
cookie = await cookieWithBiliTicket(cookie);
|
|
18
|
-
const res = await axios.get(url, {
|
|
19
|
-
timeout: 8000,
|
|
20
|
-
headers: lodash.merge(BiliApi.BILIBILI_DYNAMIC_SPACE_HEADERS, {
|
|
21
|
-
Cookie: `${cookie}`,
|
|
22
|
-
Host: `space.bilibili.com`
|
|
23
|
-
})
|
|
24
|
-
});
|
|
25
|
-
const htmlContent = await res.data;
|
|
26
|
-
const htmlContentRegex = /="__RENDER_DATA__"\s*type="application\/json">(.*?)<\/script>/;
|
|
27
|
-
const __RENDER_DATA__ = htmlContent.match(htmlContentRegex);
|
|
28
|
-
if (__RENDER_DATA__ && __RENDER_DATA__[1]) {
|
|
29
|
-
const decoded__RENDER_DATA__JsonString = decodeURIComponent(__RENDER_DATA__[1]);
|
|
30
|
-
const accessIdRegex = /"access_id":"(.*?)"/;
|
|
31
|
-
const access_id = decoded__RENDER_DATA__JsonString.match(accessIdRegex);
|
|
32
|
-
const ExpirationTimeRegex = /document.getElementById\("__RENDER_DATA__"\).*?setTimeout\(function\(\)\s*{window.location.reload\(true\);},\s*(\d+)\s*\*\s*(\d+)\);<\/script>/;
|
|
33
|
-
const ExpirationTime = htmlContent.match(ExpirationTimeRegex);
|
|
34
|
-
if (access_id && access_id[1] && ExpirationTime && ExpirationTime[1]) {
|
|
35
|
-
await Redis.set(w_webid_key, access_id[1], { EX: Number(ExpirationTime[1]) });
|
|
36
|
-
return String(access_id[1]);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
console.error('Failed to get access_id from __RENDER_DATA__');
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { getWebId };
|