yz-yuki-plugin 2.0.4-6 → 2.0.4-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/README.md CHANGED
@@ -196,6 +196,10 @@ https://m.weibo.cn/u/7643376782 # 7643376782 为崩坏星穹铁道博主uid
196
196
 
197
197
  有意见或者建议也欢迎提交 [Issues](https://github.com/snowtafir/yuki-plugin/issues) 和 [Pull requests](https://github.com/snowtafir/yuki-plugin/pulls)。
198
198
 
199
+ > [!TIP]
200
+ > 1. main、main3分支为编译分支,请勿直接在该分支上进行开发,请使用dev、dev3、npm分支进行同步开发,并提交Pull requests。
201
+ > 2. 提交PR后由管理员审核,审核成功并合并后会自动进行github actions编译,最终提交编译好的代码到main、main3分支以及发布到npm。
202
+
199
203
  # 🌟 六、license/声明
200
204
  - this project is inspired by [trss-xianxin-plugin](https://github.com/snowtafir/xianxin-plugin)
201
205
  - 基于 `MIT` 协议开源,但有如下额外限制:
@@ -26,7 +26,7 @@ class BiliTask {
26
26
  else if (resjson.code === -352) {
27
27
  await postGateway(cookie);
28
28
  if (count < 3) {
29
- await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * (10500 - 2000 + 1) + 2000))); // 随机延时2-10.5
29
+ await this.randomDelay(2000, 8000); // 随机延时2-8
30
30
  await this.hendleEventDynamicData(uid, count + 1);
31
31
  logger.error(`获取 ${uid} 动态,Gateway count:${String(count)}`);
32
32
  }
@@ -58,6 +58,7 @@ class BiliTask {
58
58
  * @param lastLiveStatus 最后直播状态
59
59
  */
60
60
  async processBiliData(biliPushData, uidMap, dynamicList, lastLiveStatus) {
61
+ const requestedDataOfUids = new Map(); // 存放已请求的 uid 映射
61
62
  for (let chatType in biliPushData) { // 遍历 group 和 private
62
63
  if (!uidMap.has(chatType)) {
63
64
  uidMap.set(chatType, new Map());
@@ -69,7 +70,15 @@ class BiliTask {
69
70
  if (!lastLiveStatus[subInfoOfup.uid]) {
70
71
  lastLiveStatus[subInfoOfup.uid] = 0;
71
72
  }
72
- const resp = await this.hendleEventDynamicData(subInfoOfup.uid);
73
+ let resp;
74
+ // 检查是否已经请求过该 uid
75
+ if (requestedDataOfUids.has(subInfoOfup.uid)) {
76
+ resp = requestedDataOfUids.get(subInfoOfup.uid); // 从已请求的映射中获取响应数据
77
+ }
78
+ else {
79
+ resp = await this.hendleEventDynamicData(subInfoOfup.uid);
80
+ requestedDataOfUids.set(subInfoOfup.uid, resp); // 将响应数据存储到映射中
81
+ }
73
82
  if (resp) {
74
83
  if (resp.code === 0) {
75
84
  const dynamicData = resp.data?.items || [];
@@ -92,10 +101,11 @@ class BiliTask {
92
101
  const bot_id = subInfoOfup.bot_id || [];
93
102
  const { name, type } = subInfoOfup;
94
103
  chatTypeMap.set(subInfoOfup.uid, { chatIds, bot_id, upName: name, type });
95
- await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * (8000 - 2000 + 1) + 2000))); // 随机延时2-8
104
+ await this.randomDelay(1000, 4000); // 随机延时1-4
96
105
  }
97
106
  }
98
107
  }
108
+ requestedDataOfUids.clear(); // 清空已请求的映射
99
109
  }
100
110
  /**
101
111
  * 推送动态消息
@@ -137,7 +147,7 @@ class BiliTask {
137
147
  if (type && type.length && !type.includes(pushDynamicData.type))
138
148
  continue; // 如果禁用了某类型的动态推送,跳过当前循环
139
149
  await this.sendDynamic(chatId, bot_id, upName, pushDynamicData, biliConfigData, chatType); // 发送动态消息
140
- await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * (6500 - 2000 + 1) + 2000))); // 随机延时2-6.5
150
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
141
151
  }
142
152
  }
143
153
  }
@@ -190,7 +200,7 @@ class BiliTask {
190
200
  for (let i = 0; i < imgs.length; i++) {
191
201
  const image = imgs[i];
192
202
  await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
193
- await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * (6500 - 2000 + 1) + 2000))); // 随机延时2-6.5
203
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
194
204
  }
195
205
  await new Promise((resolve) => setTimeout(resolve, 1000)); // 休眠1秒
196
206
  }
@@ -32,6 +32,7 @@ class WeiboTask {
32
32
  * @param dynamicList 动态列表
33
33
  */
34
34
  async processWeiboData(weiboPushData, uidMap, dynamicList) {
35
+ const requestedDataOfUids = new Map(); // 存放已请求的 uid 映射
35
36
  for (let chatType in weiboPushData) { // 遍历 group 和 private
36
37
  if (!uidMap.has(chatType)) {
37
38
  uidMap.set(chatType, new Map());
@@ -40,7 +41,15 @@ class WeiboTask {
40
41
  for (let chatId in weiboPushData[chatType]) {
41
42
  const subUpsOfChat = Array.prototype.slice.call(weiboPushData[chatType][chatId] || []);
42
43
  for (let subInfoOfup of subUpsOfChat) {
43
- const resp = await new WeiboGetWebData().getBloggerDynamicList(subInfoOfup.uid); // 获取指定 uid 的动态列表
44
+ let resp;
45
+ // 检查是否已经请求过该 uid
46
+ if (requestedDataOfUids.has(subInfoOfup.uid)) {
47
+ resp = requestedDataOfUids.get(subInfoOfup.uid); // 从已请求的映射中获取响应数据
48
+ }
49
+ else {
50
+ resp = await await new WeiboGetWebData().getBloggerDynamicList(subInfoOfup.uid); // 获取指定 uid 的动态列表
51
+ requestedDataOfUids.set(subInfoOfup.uid, resp); // 将响应数据存储到映射中
52
+ }
44
53
  if (resp) {
45
54
  const dynamicData = resp || [];
46
55
  dynamicList[subInfoOfup.uid] = dynamicData;
@@ -53,6 +62,7 @@ class WeiboTask {
53
62
  }
54
63
  }
55
64
  }
65
+ requestedDataOfUids.clear(); // 清空已请求的映射
56
66
  }
57
67
  /**
58
68
  * 推送动态消息
@@ -95,7 +105,7 @@ class WeiboTask {
95
105
  if (type && type.length && !type.includes(pushDynamicData.type))
96
106
  continue; // 如果禁用了某类型的动态推送,跳过当前循环
97
107
  await this.sendDynamic(chatId, bot_id, upName, pushDynamicData, weiboConfigData, chatType); // 发送动态消息
98
- await this.randomDelay(2000, 10500); // 随机延时2-10.5
108
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
99
109
  }
100
110
  }
101
111
  }
@@ -156,9 +166,9 @@ class WeiboTask {
156
166
  for (let i = 0; i < imgs.length; i++) {
157
167
  const image = imgs[i];
158
168
  await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
159
- await this.randomDelay(2000, 6500); // 随机延时2-6.5
169
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
160
170
  }
161
- await this.randomDelay(1000, 2000);
171
+ await new Promise((resolve) => setTimeout(resolve, 1000));
162
172
  }
163
173
  else {
164
174
  const dynamicMsg = await WeiboQuery.formatTextDynamicData(upName, pushDynamicData, false, weiboConfigData); //构建文字动态消息
@@ -173,7 +183,7 @@ class WeiboTask {
173
183
  }
174
184
  }
175
185
  await this.sendMessage(chatId, bot_id, chatType, dynamicMsg);
176
- await this.randomDelay(1000, 2000);
186
+ await new Promise((resolve) => setTimeout(resolve, 1000));
177
187
  }
178
188
  }
179
189
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.4-6",
3
+ "version": "2.0.4-7",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",