yz-yuki-plugin 2.0.6-12 → 2.0.6-13
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 +1 -0
- package/lib/apps/bilibili.js +9 -9
- package/lib/apps/weibo.js +7 -7
- package/lib/models/bilibili/bilibili.main.get.web.data.js +41 -6
- package/lib/models/bilibili/bilibili.main.models.js +2 -2
- package/lib/models/bilibili/bilibili.main.task.js +5 -3
- package/lib/models/weibo/weibo.main.get.web.data.js +43 -11
- package/lib/models/weibo/weibo.main.task.js +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/apps/bilibili.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Messages, Redis } from 'yunzaijs';
|
|
|
4
4
|
import { BiliQuery } from '../models/bilibili/bilibili.main.query.js';
|
|
5
5
|
import { BiliTask } from '../models/bilibili/bilibili.main.task.js';
|
|
6
6
|
import Config from '../utils/config.js';
|
|
7
|
-
import {
|
|
7
|
+
import { BilibiliWebDataFetcher } from '../models/bilibili/bilibili.main.get.web.data.js';
|
|
8
8
|
import { readLoginCookie, applyLoginQRCode, pollLoginQRCode, saveLoginCookie, postGateway, exitBiliLogin, checkBiliLogin, readSavedCookieItems, saveLocalBiliCk, readSyncCookie, getNewTempCk, saveTempCk } from '../models/bilibili/bilibili.main.models.js';
|
|
9
9
|
|
|
10
10
|
const message = new Messages('message');
|
|
@@ -52,8 +52,8 @@ message.use(async (e) => {
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
// 获取 Bilibili 动态信息
|
|
55
|
-
const res = await new
|
|
56
|
-
if (res
|
|
55
|
+
const res = await new BilibiliWebDataFetcher(e).getBiliDynamicListDataByUid(uid);
|
|
56
|
+
if (res?.statusText !== 'OK') {
|
|
57
57
|
e.reply('出了点网络问题,等会再试试吧~');
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
@@ -66,8 +66,8 @@ message.use(async (e) => {
|
|
|
66
66
|
let infoName = '';
|
|
67
67
|
if (code === 0 && has_more === false) {
|
|
68
68
|
e.reply(`检测到该uid的主页空间动态内容为空,\n执行uid:${uid} 校验...`);
|
|
69
|
-
const resp = await new
|
|
70
|
-
if (resp
|
|
69
|
+
const resp = await new BilibiliWebDataFetcher(e).getBilibiUserInfoByUid(uid);
|
|
70
|
+
if (resp?.statusText !== 'OK') {
|
|
71
71
|
e.reply('出了点网络问题,发起uid校验失败,等会再试试吧~');
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
@@ -438,8 +438,8 @@ message.use(async (e) => {
|
|
|
438
438
|
/**通过uid获取up主信息 */
|
|
439
439
|
message.use(async (e) => {
|
|
440
440
|
let uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(b站|B站|bili|bilibili|哔哩|哔哩哔哩)(up|UP)主/g, '').trim();
|
|
441
|
-
const res = await new
|
|
442
|
-
if (res
|
|
441
|
+
const res = await new BilibiliWebDataFetcher(e).getBilibiUserInfoByUid(uid);
|
|
442
|
+
if (res?.statusText !== 'OK') {
|
|
443
443
|
e.reply('诶嘿,出了点网络问题,等会再试试吧~');
|
|
444
444
|
return;
|
|
445
445
|
}
|
|
@@ -466,8 +466,8 @@ message.use(async (e) => {
|
|
|
466
466
|
/** 根据名称搜索up的uid*/
|
|
467
467
|
message.use(async (e) => {
|
|
468
468
|
let keyword = e.msg.replace(/^(#|\/)(yuki|优纪)?搜索(b站|B站|bili|bilibili|哔哩|哔哩哔哩)(up|UP)主/g, '').trim();
|
|
469
|
-
const res = await new
|
|
470
|
-
if (res
|
|
469
|
+
const res = await new BilibiliWebDataFetcher(e).searchBiliUserInfoByKeyword(keyword);
|
|
470
|
+
if (res?.statusText !== 'OK') {
|
|
471
471
|
e.reply('诶嘿,出了点网络问题,等会再试试吧~');
|
|
472
472
|
return;
|
|
473
473
|
}
|
package/lib/apps/weibo.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Messages } from 'yunzaijs';
|
|
|
2
2
|
import { WeiboQuery } from '../models/weibo/weibo.main.query.js';
|
|
3
3
|
import { WeiboTask } from '../models/weibo/weibo.main.task.js';
|
|
4
4
|
import Config from '../utils/config.js';
|
|
5
|
-
import {
|
|
5
|
+
import { WeiboWebDataFetcher } from '../models/weibo/weibo.main.get.web.data.js';
|
|
6
6
|
|
|
7
7
|
const message = new Messages('message');
|
|
8
8
|
let weiboPushData = Config.getConfigData('config', 'weibo', 'push');
|
|
@@ -46,8 +46,8 @@ message.use(async (e) => {
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
// 获取 微博 博主信息
|
|
49
|
-
const res = await new
|
|
50
|
-
if (res
|
|
49
|
+
const res = await new WeiboWebDataFetcher(e).getBloggerInfo(uid);
|
|
50
|
+
if (res?.statusText !== 'OK') {
|
|
51
51
|
e.reply('出了点网络问题,等会再试试吧~');
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
@@ -211,8 +211,8 @@ message.use(async (e) => {
|
|
|
211
211
|
/**通过uid获取up主信息 */
|
|
212
212
|
message.use(async (e) => {
|
|
213
213
|
let uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(微博|weibo|WEIBO)(博|bo|BO)主/g, '').trim();
|
|
214
|
-
const res = await new
|
|
215
|
-
if (res
|
|
214
|
+
const res = await new WeiboWebDataFetcher(e).getBloggerInfo(uid);
|
|
215
|
+
if (res?.statusText !== 'OK') {
|
|
216
216
|
e.reply('诶嘿,出了点网络问题,等会再试试吧~');
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
@@ -240,8 +240,8 @@ message.use(async (e) => {
|
|
|
240
240
|
/** 根据昵称搜索博主信息*/
|
|
241
241
|
message.use(async (e) => {
|
|
242
242
|
let keyword = e.msg.replace(/^(#|\/)(yuki|优纪)?搜索(微博|weibo|WEIBO)(博|bo|BO)主/g, '').trim();
|
|
243
|
-
const res = await new
|
|
244
|
-
if (res
|
|
243
|
+
const res = await new WeiboWebDataFetcher(e).searchBloggerInfo(keyword);
|
|
244
|
+
if (res?.statusText !== 'OK') {
|
|
245
245
|
e.reply('诶嘿,出了点网络问题,等会再试试吧~');
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import https from 'https';
|
|
2
3
|
import lodash from 'lodash';
|
|
3
4
|
import BiliApi from './bilibili.main.api.js';
|
|
4
5
|
import { readSyncCookie, cookieWithBiliTicket, readSavedCookieItems, readSavedCookieOtherItems } from './bilibili.main.models.js';
|
|
@@ -6,8 +7,39 @@ import { getWbiSign } from './bilibili.risk.wbi.js';
|
|
|
6
7
|
import { getDmImg } from './bilibili.risk.dm.img.js';
|
|
7
8
|
import { getWebId } from './bilibili.risk.w_webid.js';
|
|
8
9
|
|
|
9
|
-
class
|
|
10
|
-
|
|
10
|
+
class BiliHttpClient {
|
|
11
|
+
client;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.client = this.initializeClient();
|
|
14
|
+
}
|
|
15
|
+
initializeClient() {
|
|
16
|
+
const httpsAgent = new https.Agent({
|
|
17
|
+
keepAlive: true,
|
|
18
|
+
maxSockets: 100,
|
|
19
|
+
timeout: 20000
|
|
20
|
+
});
|
|
21
|
+
const client = axios.create({
|
|
22
|
+
httpsAgent: httpsAgent,
|
|
23
|
+
timeout: 20000
|
|
24
|
+
});
|
|
25
|
+
return client;
|
|
26
|
+
}
|
|
27
|
+
async request(url, config) {
|
|
28
|
+
try {
|
|
29
|
+
const response = await this.client.request({ url, ...config });
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error('BiliHttpClient Request failed:', error);
|
|
34
|
+
// 重新创建 AxiosInstance
|
|
35
|
+
this.client = this.initializeClient();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class BilibiliWebDataFetcher extends BiliHttpClient {
|
|
40
|
+
constructor(e) {
|
|
41
|
+
super();
|
|
42
|
+
}
|
|
11
43
|
/**通过uid获取up动态数据表*/
|
|
12
44
|
async getBiliDynamicListDataByUid(uid) {
|
|
13
45
|
const url = BiliApi.BILIBIL_API.biliDynamicInfoList;
|
|
@@ -32,7 +64,8 @@ class BiliGetWebData {
|
|
|
32
64
|
w_rid: w_rid,
|
|
33
65
|
wts: time_stamp
|
|
34
66
|
};
|
|
35
|
-
const res = await
|
|
67
|
+
const res = await this.request(url, {
|
|
68
|
+
method: 'GET',
|
|
36
69
|
params,
|
|
37
70
|
timeout: 10000,
|
|
38
71
|
headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
@@ -67,7 +100,8 @@ class BiliGetWebData {
|
|
|
67
100
|
w_rid: w_rid,
|
|
68
101
|
wts: time_stamp
|
|
69
102
|
};
|
|
70
|
-
const res = await
|
|
103
|
+
const res = await this.request(url, {
|
|
104
|
+
method: 'GET',
|
|
71
105
|
params,
|
|
72
106
|
timeout: 5000,
|
|
73
107
|
headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
@@ -97,7 +131,8 @@ class BiliGetWebData {
|
|
|
97
131
|
w_rid: w_rid,
|
|
98
132
|
wts: time_stamp
|
|
99
133
|
};
|
|
100
|
-
const res = await
|
|
134
|
+
const res = await this.request(url, {
|
|
135
|
+
method: 'GET',
|
|
101
136
|
params,
|
|
102
137
|
timeout: 5000,
|
|
103
138
|
headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
@@ -111,4 +146,4 @@ class BiliGetWebData {
|
|
|
111
146
|
}
|
|
112
147
|
}
|
|
113
148
|
|
|
114
|
-
export {
|
|
149
|
+
export { BilibiliWebDataFetcher };
|
|
@@ -145,8 +145,8 @@ async function checkBiliLogin(e) {
|
|
|
145
145
|
let current_exp = level_info?.current_exp;
|
|
146
146
|
let next_exp = level_info?.next_exp;
|
|
147
147
|
const LoginCookieTTL = await readLoginCookieTTL();
|
|
148
|
-
const LoginCookieTTLStr = LoginCookieTTL === -1 ? '永久' : LoginCookieTTL === -2 ? '
|
|
149
|
-
e.reply(`~B
|
|
148
|
+
const LoginCookieTTLStr = LoginCookieTTL === -1 ? '永久' : LoginCookieTTL === -2 ? '-' : `${new Date(Date.now() + LoginCookieTTL * 1000).toLocaleString()}`;
|
|
149
|
+
e.reply(`~B站账号已登陆~\n有效期至:${LoginCookieTTLStr}。\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}`);
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
// 处理其他情况
|
|
@@ -2,7 +2,7 @@ import QRCode from 'qrcode';
|
|
|
2
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 {
|
|
5
|
+
import { BilibiliWebDataFetcher } from './bilibili.main.get.web.data.js';
|
|
6
6
|
import { readSyncCookie, postGateway } from './bilibili.main.models.js';
|
|
7
7
|
import { BiliQuery } from './bilibili.main.query.js';
|
|
8
8
|
|
|
@@ -10,16 +10,18 @@ class BiliTask {
|
|
|
10
10
|
taskName;
|
|
11
11
|
groupKey;
|
|
12
12
|
privateKey;
|
|
13
|
+
BilibiliWebDataFetcher;
|
|
13
14
|
e;
|
|
14
15
|
constructor(e) {
|
|
15
16
|
this.taskName = 'biliTask';
|
|
16
17
|
this.groupKey = 'Yz:yuki:bili:upPush:group:';
|
|
17
18
|
this.privateKey = 'Yz:yuki:bili:upPush:private:';
|
|
19
|
+
this.BilibiliWebDataFetcher = new BilibiliWebDataFetcher();
|
|
18
20
|
}
|
|
19
21
|
async hendleEventDynamicData(uid, count = 0) {
|
|
20
22
|
let { cookie } = await readSyncCookie();
|
|
21
|
-
const resp = await
|
|
22
|
-
const resjson = await resp
|
|
23
|
+
const resp = await this.BilibiliWebDataFetcher.getBiliDynamicListDataByUid(uid);
|
|
24
|
+
const resjson = await resp?.data;
|
|
23
25
|
if (!resjson || resjson.code !== 0 || resjson.code === -352) {
|
|
24
26
|
await postGateway(cookie);
|
|
25
27
|
if (count < 2) {
|
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import https from 'https';
|
|
2
3
|
import { WeiboApi } from './weibo.main.api.js';
|
|
3
4
|
import { WeiboQuery } from './weibo.main.query.js';
|
|
4
5
|
|
|
5
|
-
class
|
|
6
|
+
class WeiboHttpClient {
|
|
7
|
+
client;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.client = this.initializeClient();
|
|
10
|
+
}
|
|
11
|
+
initializeClient() {
|
|
12
|
+
const httpsAgent = new https.Agent({
|
|
13
|
+
keepAlive: true,
|
|
14
|
+
maxSockets: 100,
|
|
15
|
+
timeout: 20000
|
|
16
|
+
});
|
|
17
|
+
const client = axios.create({
|
|
18
|
+
httpsAgent: httpsAgent,
|
|
19
|
+
timeout: 20000
|
|
20
|
+
});
|
|
21
|
+
return client;
|
|
22
|
+
}
|
|
23
|
+
async request(url, config) {
|
|
24
|
+
try {
|
|
25
|
+
const response = await this.client.request({ url, ...config });
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('WeiboHttpClient Request failed:', error);
|
|
30
|
+
// 重新创建 AxiosInstance
|
|
31
|
+
this.client = this.initializeClient();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class WeiboWebDataFetcher extends WeiboHttpClient {
|
|
6
36
|
e;
|
|
7
|
-
constructor(e) {
|
|
37
|
+
constructor(e) {
|
|
38
|
+
super();
|
|
39
|
+
}
|
|
8
40
|
/**通过uid获取博主信息 */
|
|
9
41
|
async getBloggerInfo(target) {
|
|
10
42
|
const param = { containerid: '100505' + target };
|
|
11
43
|
const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
|
|
12
44
|
url.search = new URLSearchParams(param).toString();
|
|
13
|
-
const resp = await
|
|
14
|
-
|
|
45
|
+
const resp = await this.request(url.toString(), {
|
|
46
|
+
method: 'GET',
|
|
15
47
|
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
16
48
|
});
|
|
17
49
|
return resp;
|
|
@@ -22,9 +54,9 @@ class WeiboGetWebData {
|
|
|
22
54
|
const params = {
|
|
23
55
|
q: keyword
|
|
24
56
|
};
|
|
25
|
-
const resp = await
|
|
57
|
+
const resp = await this.request(url, {
|
|
58
|
+
method: 'GET',
|
|
26
59
|
params,
|
|
27
|
-
timeout: 10000,
|
|
28
60
|
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://s.weibo.com' }
|
|
29
61
|
});
|
|
30
62
|
return resp;
|
|
@@ -36,13 +68,13 @@ class WeiboGetWebData {
|
|
|
36
68
|
url.search = new URLSearchParams(params).toString();
|
|
37
69
|
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * (6500 - 1000 + 1) + 1000)));
|
|
38
70
|
try {
|
|
39
|
-
const response = await
|
|
40
|
-
|
|
71
|
+
const response = await this.request(url.toString(), {
|
|
72
|
+
method: 'GET',
|
|
41
73
|
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
42
74
|
});
|
|
43
|
-
const { ok, data, msg } = response
|
|
75
|
+
const { ok, data, msg } = response?.data;
|
|
44
76
|
if (!ok && msg !== '这里还没有内容') {
|
|
45
|
-
throw new Error(response
|
|
77
|
+
throw new Error(response?.config.url);
|
|
46
78
|
}
|
|
47
79
|
return data.cards.filter(WeiboQuery.filterCardTypeCustom);
|
|
48
80
|
}
|
|
@@ -53,4 +85,4 @@ class WeiboGetWebData {
|
|
|
53
85
|
}
|
|
54
86
|
}
|
|
55
87
|
|
|
56
|
-
export {
|
|
88
|
+
export { WeiboWebDataFetcher };
|
|
@@ -2,18 +2,20 @@ import QRCode from 'qrcode';
|
|
|
2
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 {
|
|
5
|
+
import { WeiboWebDataFetcher } from './weibo.main.get.web.data.js';
|
|
6
6
|
import { WeiboQuery } from './weibo.main.query.js';
|
|
7
7
|
|
|
8
8
|
class WeiboTask {
|
|
9
9
|
taskName;
|
|
10
10
|
groupKey;
|
|
11
11
|
privateKey;
|
|
12
|
+
WeiboWebDataFetcher;
|
|
12
13
|
e;
|
|
13
14
|
constructor(e) {
|
|
14
15
|
this.taskName = 'weiboTask';
|
|
15
16
|
this.groupKey = 'Yz:yuki:weibo:upPush:group:';
|
|
16
17
|
this.privateKey = 'Yz:yuki:weibo:upPush:private:';
|
|
18
|
+
this.WeiboWebDataFetcher = new WeiboWebDataFetcher(e);
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* 执行动态推送任务
|
|
@@ -59,7 +61,7 @@ class WeiboTask {
|
|
|
59
61
|
dynamicList[subInfoOfup.uid] = dynamicData;
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
|
-
resp = await
|
|
64
|
+
resp = await this.WeiboWebDataFetcher.getBloggerDynamicList(subInfoOfup.uid); // 获取指定 uid 的动态列表
|
|
63
65
|
if (resp) {
|
|
64
66
|
requestedDataOfUids.set(subInfoOfup.uid, resp); // 将响应数据存储到映射中
|
|
65
67
|
const dynamicData = resp || [];
|