yz-yuki-plugin 2.0.6-14 → 2.0.6-16

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  # 2.0.6
2
+ * 新增 weibo User-Agent 配置项
2
3
  * 优化api请求
3
4
  * 优化消息发送
4
5
  * 优化文字动态图片资源的发送
@@ -7,7 +8,7 @@
7
8
 
8
9
  # 2.0.5
9
10
  * 优化ck
10
- * 新增 User-Agent 配置项
11
+ * 新增 bili User-Agent 配置项
11
12
  * 优化获取动态数据
12
13
  * 新增获取B站up数据的随机延迟配置项
13
14
  * 新增puppeteer渲染图片测试脚本
@@ -11,6 +11,13 @@ pushStatus: 1
11
11
  # ❀请勿设置周期过短比如小于10分钟,以免触发访问限制。
12
12
  checkDynamicCD: '*/23 * * * *'
13
13
 
14
+ # 请求头 User-Agent 列表。请根据需要自行添加或修改。
15
+ # 可设置多个请求头,每次重启后会随机选择一个。获取方法请浏览器自行搜索。
16
+ userAgentList:
17
+ - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
18
+ #- Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
19
+ #- Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
20
+
14
21
  # 筛选何时发布的动态,单位为秒,默认7200秒即2小时,即以当前时间为基准,筛选过去2小时内发布的动态,并推送。
15
22
  # 取值范围:3600-36000秒,即过去的1-10h。应大于checkDynamicCD的周期。
16
23
  dynamicTimeRange: 7200
@@ -39,7 +39,7 @@ class BiliTask {
39
39
  async runTask() {
40
40
  let biliConfigData = await Config.getUserConfig('bilibili', 'config');
41
41
  let biliPushData = await Config.getUserConfig('bilibili', 'push');
42
- let dynamicTimeRange = biliConfigData?.dynamicTimeRange || 7200; // 检测动态的冷却时间,单位为秒,默认2小时
42
+ let dynamicTimeRange = biliConfigData?.dynamicTimeRange || 7200; // 筛选何时发布的动态,单位为秒,默认2小时内发布的动态
43
43
  logger.debug(`当前B站功能配置:${JSON.stringify(biliConfigData)}`);
44
44
  const uidMap = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
45
45
  const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组
@@ -115,10 +115,10 @@ class BiliTask {
115
115
  * @param uidMap uid 映射
116
116
  * @param dynamicList 动态列表
117
117
  * @param now 当前时间戳
118
- * @param interval 检测动态的冷却时间
118
+ * @param dynamicTimeRange 筛选何时发布的动态
119
119
  * @param biliConfigData Bilibili配置数据
120
120
  */
121
- async makeUidDynamicDataMap(uidMap, dynamicList, now, interval, biliConfigData, messageMap) {
121
+ async makeUidDynamicDataMap(uidMap, dynamicList, now, dynamicTimeRange, biliConfigData, messageMap) {
122
122
  for (let [chatType, chatTypeMap] of uidMap) {
123
123
  for (let [key, value] of chatTypeMap) {
124
124
  const tempDynamicList = dynamicList[key] || [];
@@ -132,7 +132,7 @@ class BiliTask {
132
132
  }
133
133
  if (!author?.pub_ts)
134
134
  continue; // 如果动态没有发布时间,跳过当前循环
135
- if (Number(now - author.pub_ts) > interval) {
135
+ if (Number(now - author.pub_ts) > dynamicTimeRange) {
136
136
  logger.debug(`超过间隔,跳过 [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
137
137
  continue;
138
138
  } // 如果超过推送时间间隔,跳过当前循环
@@ -1,21 +1,47 @@
1
+ import Config from '../../utils/config.js';
2
+
1
3
  class WeiboApi {
2
- static WEIBO_API = {
3
- weiboGetIndex: 'https://m.weibo.cn/api/container/getIndex',
4
- //通过关键词${upKeyword}搜索博主 parama = { q: 'Keyword'},
5
- weiboAjaxSearch: 'https://weibo.com/ajax/side/search'
6
- };
4
+ weiboConfigData;
5
+ USER_AGENT;
6
+ constructor() {
7
+ this.weiboConfigData = Config.getUserConfig('weibo', 'config');
8
+ this.USER_AGENT = WeiboApi.WEIBO_USER_AGENT;
9
+ this.initialize();
10
+ }
11
+ static WEIBO_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36';
12
+ //初始化User-Agent
13
+ async initialize() {
14
+ await this.initUserAgent();
15
+ }
16
+ async initUserAgent() {
17
+ const userAgentList = await this.weiboConfigData.userAgentList;
18
+ if (userAgentList && userAgentList.length > 0) {
19
+ const randomIndex = Math.floor(Math.random() * userAgentList.length);
20
+ this.USER_AGENT = String(userAgentList[randomIndex]);
21
+ }
22
+ }
23
+ get WEIBO_API() {
24
+ return {
25
+ weiboGetIndex: 'https://m.weibo.cn/api/container/getIndex',
26
+ //通过关键词${upKeyword}搜索博主 parama = { q: 'Keyword'},
27
+ weiboAjaxSearch: 'https://weibo.com/ajax/side/search'
28
+ };
29
+ }
7
30
  /**统一设置header */
8
- static WEIBO_HEADERS = {
9
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
10
- 'Accept-language': 'zh-CN,zh;q=0.9',
11
- 'Authority': 'm.weibo.cn',
12
- 'Cache-control': 'max-age=0',
13
- 'Sec-fetch-dest': 'empty',
14
- 'Sec-fetch-mode': 'same-origin',
15
- 'Sec-fetch-site': 'same-origin',
16
- 'Upgrade-insecure-requests': '1',
17
- 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
18
- };
31
+ get WEIBO_HEADERS() {
32
+ return {
33
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
34
+ 'Accept-language': 'zh-CN,zh;q=0.9',
35
+ 'Authority': 'm.weibo.cn',
36
+ 'Cache-control': 'max-age=0',
37
+ 'Sec-fetch-dest': 'empty',
38
+ 'Sec-fetch-mode': 'same-origin',
39
+ 'Sec-fetch-site': 'same-origin',
40
+ 'Upgrade-insecure-requests': '1',
41
+ 'User-agent': this.USER_AGENT
42
+ };
43
+ }
19
44
  }
45
+ var WeiboApi$1 = new WeiboApi();
20
46
 
21
- export { WeiboApi };
47
+ export { WeiboApi$1 as default };
@@ -1,5 +1,5 @@
1
1
  import axios from 'axios';
2
- import { WeiboApi } from './weibo.main.api.js';
2
+ import WeiboApi from './weibo.main.api.js';
3
3
  import { WeiboQuery } from './weibo.main.query.js';
4
4
 
5
5
  class WeiboWebDataFetcher {
@@ -1,6 +1,6 @@
1
1
  import moment from 'moment';
2
2
  import fetch from 'node-fetch';
3
- import { WeiboApi } from './weibo.main.api.js';
3
+ import WeiboApi from './weibo.main.api.js';
4
4
  import { Segment } from 'yunzaijs';
5
5
  import { JSDOM } from 'jsdom';
6
6
 
@@ -21,7 +21,7 @@ class WeiboTask {
21
21
  async runTask() {
22
22
  let weiboConfigData = await Config.getUserConfig('weibo', 'config');
23
23
  let weiboPushData = await Config.getUserConfig('weibo', 'push');
24
- let interval = weiboConfigData.interval || 7200; // 检测动态的冷却时间,单位为秒,默认2小时
24
+ let interval = weiboConfigData.interval || 7200; // 筛选何时发布的动态,单位为秒,默认2小时内发布的动态
25
25
  logger.debug(`当前微博功能配置:${JSON.stringify(weiboConfigData)}`);
26
26
  const uidMap = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
27
27
  const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组
@@ -81,10 +81,10 @@ class WeiboTask {
81
81
  * @param uidMap uid 映射
82
82
  * @param dynamicList 动态列表
83
83
  * @param now 当前时间戳
84
- * @param interval 检测动态的冷却时间
84
+ * @param dynamicTimeRange 筛选何时发布的动态
85
85
  * @param weiboConfigData 微博配置数据
86
86
  */
87
- async makeUidDynamicDataMap(uidMap, dynamicList, now, interval, weiboConfigData, messageMap) {
87
+ async makeUidDynamicDataMap(uidMap, dynamicList, now, dynamicTimeRange, weiboConfigData, messageMap) {
88
88
  for (let [chatType, chatTypeMap] of uidMap) {
89
89
  for (let [key, value] of chatTypeMap) {
90
90
  const tempDynamicList = dynamicList[key] || [];
@@ -99,7 +99,7 @@ class WeiboTask {
99
99
  }
100
100
  if (!raw_post?.mblog?.created_at)
101
101
  continue;
102
- if (Number(now - WeiboQuery.getDynamicCreatetDate(raw_post) / 1000) > interval) {
102
+ if (Number(now - WeiboQuery.getDynamicCreatetDate(raw_post) / 1000) > dynamicTimeRange) {
103
103
  logger.debug(`超过间隔,跳过 [ ${user?.screen_name} : ${user?.id} ] ${raw_post?.mblog?.created_at} 的动态`);
104
104
  continue;
105
105
  } // 如果超过推送时间间隔,跳过当前循环
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.6-14",
3
+ "version": "2.0.6-16",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "md5": "^2.3.0",
37
37
  "moment": "^2.30.1",
38
38
  "node-fetch": "^3.3.2",
39
- "puppeteer": "^24.1.0",
39
+ "puppeteer": "^24.4.0",
40
40
  "qrcode": "^1.5.4",
41
41
  "react": "^18.3.1",
42
42
  "react-dom": "^18.3.1",
@@ -70,7 +70,7 @@
70
70
  "node-fetch": "^3.3.2",
71
71
  "postcss": "^8.4.47",
72
72
  "prettier": "^3.4.2",
73
- "puppeteer": "^24.1.0",
73
+ "puppeteer": "^24.4.0",
74
74
  "qrcode": "^1.5.4",
75
75
  "react": "^18.3.1",
76
76
  "react-dom": "^18.3.1",