yz-yuki-plugin 2.0.5-0 → 2.0.5-2

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.5
2
+ * 新增获取B站up数据的随机延迟配置项
2
3
  * 新增puppeteer渲染图片测试脚本
3
4
 
4
5
  # 2.0.4
@@ -11,10 +11,14 @@ pushTime: '*/23 * * * *'
11
11
  # 推送监测间隔,单位为秒,默认7200秒即2小时,即以当前时间为基准,监测过去2小时内的动态,并推送。取值范围:3600-36000秒,即过去的1-10h。应大于pushTime的周期。
12
12
  interval: 7200
13
13
 
14
+ # 顺序检测相邻up主的动态并获取数据的最大随机间隔时间,单位为毫秒,默认 8000,即 8000 毫秒(8秒),即获取该up的动态数据后,随机等待2(内置值)-8秒后再获取下一位up的动态数据。取值范围:4000 ≦ x < pushTime的周期,单位为毫秒。
15
+ # 该数值大小影响风控概率, 请谨慎调整,建议不要设置过小,否则可能被风控导致动态获取失败。
16
+ getDataRandomDelay: 8000
17
+
14
18
  # 全部订阅的转发动态是否推送: 默认 1 - 开启推送, 0 - 关闭推送。 如果仅仅需要关闭单个订阅的转发动态推送,使用分类订阅指令不包含 转发 分类即可,无需修改此配置。
15
19
  pushTransmit: 1
16
20
 
17
- # 推送动态时,限制发送多少张图片
21
+ # 推送文字和图文动态时,限制发送多少张图片
18
22
  pushPicCountLimit: 3
19
23
 
20
24
  # 推送文字和图文动态时,限制字数是多少
@@ -205,7 +205,7 @@ message.use(async (e) => {
205
205
  if (e.isMaster) {
206
206
  await exitBiliLogin(e);
207
207
  await Redis.set('Yz:yuki:bili:loginCookie', '', { EX: 3600 * 24 * 180 });
208
- e.reply(`登陆的B站ck并已删除~`);
208
+ e.reply(`扫码登陆的B站cookie已删除~`);
209
209
  }
210
210
  else {
211
211
  e.reply('未取得bot主人身份,无权限删除B站登录ck');
@@ -60,8 +60,8 @@ async function applyLoginQRCode(e) {
60
60
  return qrcodeKey;
61
61
  }
62
62
  else {
63
- e.reply(`获取B站登录二维码失败: ${res.data.message}`);
64
- throw new Error(`获取B站登录二维码失败: ${res.data.message}`);
63
+ e.reply(`获取B站登录二维码失败: ${res.data?.message}`);
64
+ throw new Error(`获取B站登录二维码失败: ${res.data?.message}`);
65
65
  }
66
66
  }
67
67
  /**处理扫码结果 */
@@ -149,12 +149,16 @@ async function exitBiliLogin(e) {
149
149
  e.reply('当前无可用的B站登录CK可退出登录');
150
150
  return;
151
151
  }
152
- const postData = new URLSearchParams({ biliCSRF: biliCSRF });
152
+ const postData = String(biliCSRF)
153
+ .trim()
154
+ .replace(/^bili_jct=/g, '')
155
+ .replace(/;*$/g, '');
153
156
  try {
154
- const resp = await axios.post(url, postData.toString(), {
157
+ const resp = await axios.post(url, { biliCSRF: postData }, {
155
158
  headers: {
156
159
  'Host': 'passport.bilibili.com',
157
- 'Cookie': `DedeUserID=${DedeUserID}; bili_jct=${biliCSRF}; SESSDATA=${SESSDATA}`,
160
+ 'User-Agent': BiliApi.BILIBILI_HEADERS['User-Agent'],
161
+ 'Cookie': `${DedeUserID};${biliCSRF};${SESSDATA}`,
158
162
  'Content-Type': 'application/x-www-form-urlencoded'
159
163
  }
160
164
  });
@@ -163,29 +167,27 @@ async function exitBiliLogin(e) {
163
167
  e.reply('当前缓存的B站登录CK早已失效!');
164
168
  return;
165
169
  }
166
- const { code, status, data } = resp.data;
167
- logger.mark('Response Data:', data);
168
- if (status) {
169
- switch (code) {
170
- case 0:
171
- e.reply('当前缓存的B站登录CK已在服务器注销~');
172
- await Redis.set('Yz:yuki:bili:loginCookie', '', { EX: 3600 * 24 * 180 });
173
- e.reply(`登陆的B站ck并已删除~`);
174
- break;
175
- case 2202:
176
- e.reply('csrf 请求非法,退出登录请求出错');
177
- break;
178
- default:
179
- e.reply('当前缓存的B站登录CK早已失效!');
180
- }
181
- }
182
- else {
183
- e.reply('服务器响应异常,退出登录请求出错');
170
+ const res = resp.data;
171
+ logger?.debug(`exitBiliLogin: ${JSON.stringify(res)}`);
172
+ const { code } = res;
173
+ switch (code) {
174
+ case 0:
175
+ e.reply('当前缓存的B站登录CK已在B站服务器退出登录~');
176
+ break;
177
+ case 2202:
178
+ e.reply('csrf 请求非法,退出登录请求出错');
179
+ break;
180
+ case -101:
181
+ e.reply('当前缓存的扫码B站ck未登录!');
182
+ break;
183
+ default:
184
+ e.reply('未知情况!无妨');
185
+ return;
184
186
  }
185
187
  }
186
188
  catch (error) {
189
+ e.reply('退出登录请求出错');
187
190
  console.error('Error during Bili login exit:', error);
188
- e.reply('退出登录请求出错,请稍后再试');
189
191
  }
190
192
  }
191
193
  /**
@@ -397,18 +399,18 @@ async function getPayload(cookie) {
397
399
  '7003': 1, // indexedDb, !!window.indexedDB, html5 api
398
400
  '807e': 1, // cookieEnabled, navigator.cookieEnabled
399
401
  'b8ce': BiliApi.BILIBILI_HEADERS['User-Agent'], // ua "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0",
400
- '641c': 0,
401
- '07a4': 'zh-CN',
402
- '1c57': 'not available',
403
- '0bd0': 16,
404
- '748e': [1920, 1200],
405
- 'd61f': [1920, 1152],
406
- 'fc9d': -480,
407
- '6aa9': 'Asia/Shanghai',
408
- '75b8': 1,
409
- '3b21': 1,
410
- '8a1c': 0,
411
- 'd52f': 'not available',
402
+ '641c': 0, // webdriver, navigator.webdriver, like Selenium
403
+ '07a4': 'zh-CN', // language
404
+ '1c57': 'not available', // deviceMemory in GB, navigator.deviceMemory
405
+ '0bd0': 16, // hardwareConcurrency, navigator.hardwareConcurrency
406
+ '748e': [1920, 1200], // window.screen.width window.screen.height
407
+ 'd61f': [1920, 1152], // window.screen.availWidth window.screen.availHeight
408
+ 'fc9d': -480, // timezoneOffset, (new Date).getTimezoneOffset()
409
+ '6aa9': 'Asia/Shanghai', //Intl.DateTimeFormat().resolvedOptions().timeZone, // timezone, (new window.Intl.DateTimeFormat).resolvedOptions().timeZone
410
+ '75b8': 1, // sessionStorage, window.sessionStorage, html5 api
411
+ '3b21': 1, // localStorage, window.localStorage, html5 api
412
+ '8a1c': 0, // openDatabase, window.openDatabase, html5 api
413
+ 'd52f': 'not available', // cpuClass, navigator.cpuClass
412
414
  'adca': BiliApi.BILIBILI_HEADERS['User-Agent'].includes('Windows') ? 'Win32' : 'Linux', // platform, navigator.platform
413
415
  '80c9': [
414
416
  [
@@ -451,9 +453,9 @@ async function getPayload(cookie) {
451
453
  ['text/pdf', 'pdf']
452
454
  ]
453
455
  ]
454
- ],
455
- '13ab': 'f3YAAAAASUVORK5CYII=',
456
- 'bfe9': 'kABYpRAGAVYzWJooB9Bf4P+UortSvxRY0AAAAASUVORK5CYII=',
456
+ ], // plugins
457
+ '13ab': 'f3YAAAAASUVORK5CYII=', // canvas fingerprint
458
+ 'bfe9': 'kABYpRAGAVYzWJooB9Bf4P+UortSvxRY0AAAAASUVORK5CYII=', // webgl_str
457
459
  'a3c1': [
458
460
  'extensions:ANGLE_instanced_arrays;EXT_blend_minmax;EXT_color_buffer_half_float;EXT_float_blend;EXT_frag_depth;EXT_shader_texture_lod;EXT_sRGB;EXT_texture_compression_bptc;EXT_texture_compression_rgtc;EXT_texture_filter_anisotropic;OES_element_index_uint;OES_fbo_render_mipmap;OES_standard_derivatives;OES_texture_float;OES_texture_float_linear;OES_texture_half_float;OES_texture_half_float_linear;OES_vertex_array_object;WEBGL_color_buffer_float;WEBGL_compressed_texture_s3tc;WEBGL_compressed_texture_s3tc_srgb;WEBGL_debug_renderer_info;WEBGL_debug_shaders;WEBGL_depth_texture;WEBGL_draw_buffers;WEBGL_lose_context;WEBGL_provoking_vertex',
459
461
  'webgl aliased line width range:[1, 1]',
@@ -519,8 +521,8 @@ async function getPayload(cookie) {
519
521
  'webgl fragment shader low int precision:0',
520
522
  'webgl fragment shader low int precision rangeMin:31',
521
523
  'webgl fragment shader low int precision rangeMax:30'
522
- ],
523
- '6bc5': 'Google Inc. (Intel)~ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar',
524
+ ], // webgl_params, cab be set to [] if webgl is not supported
525
+ '6bc5': 'Google Inc. (Intel)~ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar', // webglVendorAndRenderer
524
526
  'ed31': 0,
525
527
  '72bd': 0,
526
528
  '097b': 0,
@@ -33,7 +33,7 @@ export declare class BiliTask {
33
33
  type: string[];
34
34
  }[];
35
35
  };
36
- }, uidMap: Map<any, Map<string, any>>, dynamicList: any, lastLiveStatus: any): Promise<void>;
36
+ }, biliConfigData: any, uidMap: Map<any, Map<string, any>>, dynamicList: any): Promise<void>;
37
37
  /**
38
38
  * 推送动态消息
39
39
  * @param uidMap uid 映射
@@ -42,11 +42,10 @@ class BiliTask {
42
42
  async runTask() {
43
43
  let biliConfigData = await Config.getUserConfig('bilibili', 'config');
44
44
  let biliPushData = await Config.getUserConfig('bilibili', 'push');
45
- let interval = biliConfigData.interval || 7200;
46
- let lastLiveStatus = JSON.parse(await Redis.get('yuki:bililive:lastlivestatus')) || {};
45
+ let interval = biliConfigData?.interval || 7200;
47
46
  const uidMap = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
48
47
  const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组
49
- await this.processBiliData(biliPushData, uidMap, dynamicList, lastLiveStatus);
48
+ await this.processBiliData(biliPushData, biliConfigData, uidMap, dynamicList);
50
49
  let now = Date.now() / 1000; // 时间戳(秒)
51
50
  await this.pushDynamicMessages(uidMap, dynamicList, now, interval, biliConfigData);
52
51
  }
@@ -57,7 +56,8 @@ class BiliTask {
57
56
  * @param dynamicList 动态列表
58
57
  * @param lastLiveStatus 最后直播状态
59
58
  */
60
- async processBiliData(biliPushData, uidMap, dynamicList, lastLiveStatus) {
59
+ async processBiliData(biliPushData, biliConfigData, uidMap, dynamicList) {
60
+ let getDataRandomDelay = biliConfigData?.getDataRandomDelay || 8000; // 获取相邻up动态数据的随机延时间隔
61
61
  const requestedDataOfUids = new Map(); // 存放已请求的 uid 映射
62
62
  for (let chatType in biliPushData) {
63
63
  // 遍历 group 和 private
@@ -68,9 +68,6 @@ class BiliTask {
68
68
  for (let chatId in biliPushData[chatType]) {
69
69
  const subUpsOfChat = Array.prototype.slice.call(biliPushData[chatType][chatId] || []);
70
70
  for (let subInfoOfup of subUpsOfChat) {
71
- if (!lastLiveStatus[subInfoOfup.uid]) {
72
- lastLiveStatus[subInfoOfup.uid] = 0;
73
- }
74
71
  let resp;
75
72
  // 检查是否已经请求过该 uid
76
73
  if (requestedDataOfUids.has(subInfoOfup.uid)) {
@@ -102,7 +99,7 @@ class BiliTask {
102
99
  const bot_id = subInfoOfup.bot_id || [];
103
100
  const { name, type } = subInfoOfup;
104
101
  chatTypeMap.set(subInfoOfup.uid, { chatIds, bot_id, upName: name, type });
105
- await this.randomDelay(1000, 4000); // 随机延时1-4秒
102
+ await this.randomDelay(2000, getDataRandomDelay); // 随机延时
106
103
  }
107
104
  }
108
105
  }
@@ -180,7 +177,7 @@ class BiliTask {
180
177
  let boxGrid = !!biliConfigData.boxGrid === false ? false : true; // 是否启用九宫格样式,默认为 true
181
178
  let isSplit = !!biliConfigData.isSplit === false ? false : true; // 是否启用分片截图,默认为 true
182
179
  let style = isSplit ? '' : `.unfold { max-height: ${biliConfigData?.noSplitHeight ?? 7500}px; }`; // 不启用分片截图模式的样式
183
- let splitHeight = biliConfigData?.splitHeight ?? 8000; // 分片截图高度,默认 8000, 单位 px,启用分片截图时生效
180
+ let splitHeight = biliConfigData?.splitHeight || 8000; // 分片截图高度,默认 8000, 单位 px,启用分片截图时生效
184
181
  const urlQrcodeData = await QRCode.toDataURL(extentData?.url);
185
182
  let renderData = this.buildRenderData(extentData, urlQrcodeData, boxGrid);
186
183
  const ScreenshotOptionsData = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.5-0",
3
+ "version": "2.0.5-2",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",