yz-yuki-plugin 2.0.7-12 → 2.0.7-14

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,6 @@
1
1
  # 2.0.7
2
+ * 优化获取B站文章动态内容
3
+ * 优化订阅数据展示
2
4
  * 修复同一up订阅多个群聊订阅,推送类型合并的问题
3
5
  * 添加白名单关键词过滤功能
4
6
  * 新增B站视频解析
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # YUKI-PLUGIN
4
4
 
5
- - 一个适用于 `Yunzai 系列机器人框架` 的B站动态、B站视频链接解析和微博动态订阅推送的插件
5
+ - 一个适用于 `Yunzai 系列机器人框架` 的B站动态、微博动态订阅推送和B站视频链接解析的插件
6
6
 
7
7
  - 支持 群聊/私聊 订阅B站动态和微博动态,支持定时推送,支持手动触发推送,支持简单查询B站/微博用户信息。
8
8
 
@@ -36,7 +36,27 @@ chromium-browser --version
36
36
  ## 选择安装方式
37
37
  按照网络情况以及使用的bot框架是`Yunzaijs`还是`Yunzai-V3`,选择对应的安装方式。
38
38
 
39
- ### ***(一)YunzaiJS***
39
+ ### ***(一)Yunzai-V3***
40
+
41
+ > 仅支持Yunzai-V3(TRSS/Miao)的分支,选择仓库,安装到 `yunzai/plugins`:
42
+
43
+ gitee仓库:
44
+ ```
45
+ git clone --branch main3 https://gitee.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
46
+ ```
47
+
48
+ github仓库:
49
+ ```
50
+ git clone --branch main3 https://github.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
51
+ ```
52
+
53
+ * 安装依赖
54
+
55
+ ```shell
56
+ pnpm install --filter=yuki-plugin
57
+ ```
58
+
59
+ ### ***(二)YunzaiJS***
40
60
  > 选择其中一种方式安装插件:
41
61
 
42
62
  1. npm包安装到`yunzaijs/node_modules`的方式,仅YunzaiJS支持:
@@ -86,26 +106,6 @@ git clone --branch main https://github.com/snowtafir/yuki-plugin.git ./plugins/y
86
106
  yarn install
87
107
  ```
88
108
 
89
- ### ***(二)Yunzai-V3***
90
-
91
- > 仅支持Yunzai-V3(TRSS/Miao)的分支,选择仓库,安装到 `yunzai/plugins`:
92
-
93
- gitee仓库:
94
- ```
95
- git clone --branch main3 https://gitee.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
96
- ```
97
-
98
- github仓库:
99
- ```
100
- git clone --branch main3 https://github.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
101
- ```
102
-
103
- * 安装依赖
104
-
105
- ```shell
106
- pnpm install --filter=yuki-plugin
107
- ```
108
-
109
109
  # 📦二、插件配置
110
110
 
111
111
  > [!IMPORTANT]
@@ -358,6 +358,17 @@ message.use(async (e) => {
358
358
  }
359
359
  else {
360
360
  let subData = Config.getConfigData('config', 'bilibili', 'push') || { group: {}, private: {} };
361
+ // 如果聊天ID没有订阅数据,则删除该聊天ID
362
+ for (let chatType in subData) {
363
+ if (subData.hasOwnProperty(chatType)) {
364
+ subData[chatType] = Object.keys(subData[chatType]).reduce((nonEmptyData, chatId) => {
365
+ if (subData[chatType][chatId].length > 0) {
366
+ nonEmptyData[chatId] = subData[chatType][chatId];
367
+ }
368
+ return nonEmptyData;
369
+ }, {});
370
+ }
371
+ }
361
372
  const messages = [];
362
373
  const typeMap = {
363
374
  DYNAMIC_TYPE_AV: '视频',
@@ -369,9 +380,9 @@ message.use(async (e) => {
369
380
  };
370
381
  // 处理群组订阅
371
382
  if (subData.group && Object.keys(subData.group).length > 0) {
372
- messages.push('------群组B站订阅------\n');
383
+ messages.push('\n>>>>>>群组B站订阅<<<<<<');
373
384
  Object.keys(subData.group).forEach(groupId => {
374
- messages.push(`群组ID:${groupId}:`);
385
+ messages.push(`\n<群组${groupId}>:`);
375
386
  subData.group[groupId].forEach((item) => {
376
387
  const types = new Set();
377
388
  if (item.type && item.type.length) {
@@ -381,15 +392,18 @@ message.use(async (e) => {
381
392
  }
382
393
  });
383
394
  }
384
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
395
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
385
396
  });
386
397
  });
387
398
  }
399
+ else {
400
+ messages.push('\n>>>>>>群组B站订阅<<<<<<\n当前没有任何群组订阅数据~');
401
+ }
388
402
  // 处理私聊订阅
389
403
  if (subData.private && Object.keys(subData.private).length > 0) {
390
- messages.push('\n------私聊B站订阅------');
404
+ messages.push('\n>>>>>>私聊B站订阅<<<<<<');
391
405
  Object.keys(subData.private).forEach(userId => {
392
- messages.push(`用户ID:${userId}:`);
406
+ messages.push(`\n<用户${userId}>:`);
393
407
  subData.private[userId].forEach((item) => {
394
408
  const types = new Set();
395
409
  if (item.type && item.type.length) {
@@ -399,16 +413,30 @@ message.use(async (e) => {
399
413
  }
400
414
  });
401
415
  }
402
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
416
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
403
417
  });
404
418
  });
405
419
  }
420
+ else {
421
+ messages.push('\n>>>>>>私聊B站订阅<<<<<<\n当前没有任何私聊订阅数据~');
422
+ }
406
423
  e.reply(`推送列表如下:\n${messages.join('\n')}`);
407
424
  }
408
425
  }, [/^(#|\/)(yuki|优纪)?(b站|B站|bili|bilibili|哔哩|哔哩哔哩)全部(推送|动态|订阅)列表$/]);
409
426
  /** 单独群聊或私聊的订阅的b站推送列表 */
410
427
  message.use(async (e) => {
411
428
  let subData = Config.getConfigData('config', 'bilibili', 'push') || { group: {}, private: {} };
429
+ // 如果聊天ID没有订阅数据,则删除该聊天ID
430
+ for (let chatType in subData) {
431
+ if (subData.hasOwnProperty(chatType)) {
432
+ subData[chatType] = Object.keys(subData[chatType]).reduce((nonEmptyData, chatId) => {
433
+ if (subData[chatType][chatId].length > 0) {
434
+ nonEmptyData[chatId] = subData[chatType][chatId];
435
+ }
436
+ return nonEmptyData;
437
+ }, {});
438
+ }
439
+ }
412
440
  const messages = [];
413
441
  const typeMap = {
414
442
  DYNAMIC_TYPE_AV: '视频',
@@ -433,7 +461,7 @@ message.use(async (e) => {
433
461
  }
434
462
  });
435
463
  }
436
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
464
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
437
465
  });
438
466
  e.reply(`推送列表如下:\n${messages.join('\n')}`);
439
467
  }, [/^(#|\/)(yuki|优纪)?(b站|B站|bili|bilibili|哔哩|哔哩哔哩)(推送|动态|订阅)列表$/]);
package/lib/apps/weibo.js CHANGED
@@ -86,16 +86,16 @@ message.use(async (e) => {
86
86
  return;
87
87
  }
88
88
  // 获取或初始化微博推送数据
89
- let data = weiboPushData || { group: {}, private: {} };
89
+ let subData = weiboPushData || { group: {}, private: {} };
90
90
  // 根据聊天类型初始化数据
91
91
  let chatType = e.isGroup ? 'group' : 'private';
92
92
  let chatId = e.isGroup ? e.group_id : e.user_id;
93
93
  // 初始化群组或私聊数据
94
- if (!data[chatType][chatId]) {
95
- data[chatType][chatId] = [];
94
+ if (!subData[chatType][chatId]) {
95
+ subData[chatType][chatId] = [];
96
96
  }
97
97
  // 查找指定UID的订阅数据
98
- const upData = data[chatType][chatId].find((item) => item.uid == uid);
98
+ const upData = subData[chatType][chatId].find((item) => item.uid == uid);
99
99
  if (!upData) {
100
100
  e.reply(`订阅列表中没有找到该UID~\n${uid}可能是无效的`);
101
101
  return;
@@ -105,7 +105,7 @@ message.use(async (e) => {
105
105
  let isDel = false;
106
106
  if (newType.length) {
107
107
  // 更新订阅类型
108
- data[chatType][chatId] = data[chatType][chatId].map(item => {
108
+ subData[chatType][chatId] = subData[chatType][chatId].map(item => {
109
109
  if (item.uid == uid) {
110
110
  item.type = newType;
111
111
  }
@@ -115,11 +115,11 @@ message.use(async (e) => {
115
115
  else {
116
116
  // 删除订阅
117
117
  isDel = true;
118
- data[chatType][chatId] = data[chatType][chatId].filter((item) => item.uid !== uid);
118
+ subData[chatType][chatId] = subData[chatType][chatId].filter((item) => item.uid !== uid);
119
119
  }
120
120
  // 保存更新后的数据
121
121
  //weiboPushData = data;
122
- Config.saveConfig('config', 'weibo', 'push', data);
122
+ Config.saveConfig('config', 'weibo', 'push', subData);
123
123
  // 回复用户操作结果
124
124
  e.reply(`${isDel ? '删除' : '修改'}微博推送成功~\n${uid}`);
125
125
  }
@@ -131,6 +131,17 @@ message.use(async (e) => {
131
131
  }
132
132
  else {
133
133
  let subData = weiboPushData || { group: {}, private: {} };
134
+ // 如果聊天ID没有订阅数据,则删除该聊天ID
135
+ for (let chatType in subData) {
136
+ if (subData.hasOwnProperty(chatType)) {
137
+ subData[chatType] = Object.keys(subData[chatType]).reduce((nonEmptyData, chatId) => {
138
+ if (subData[chatType][chatId].length > 0) {
139
+ nonEmptyData[chatId] = subData[chatType][chatId];
140
+ }
141
+ return nonEmptyData;
142
+ }, {});
143
+ }
144
+ }
134
145
  const messages = [];
135
146
  const typeMap = {
136
147
  DYNAMIC_TYPE_AV: '视频',
@@ -141,9 +152,9 @@ message.use(async (e) => {
141
152
  };
142
153
  // 处理群组订阅
143
154
  if (subData.group && Object.keys(subData.group).length > 0) {
144
- messages.push('------群组微博订阅------');
155
+ messages.push('\n>>>>>>群组微博订阅<<<<<<');
145
156
  Object.keys(subData.group).forEach(groupId => {
146
- messages.push(`群组ID:${groupId}:`);
157
+ messages.push(`\n<群组${groupId}>:`);
147
158
  subData.group[groupId].forEach((item) => {
148
159
  const types = new Set();
149
160
  if (item.type && item.type.length) {
@@ -153,15 +164,18 @@ message.use(async (e) => {
153
164
  }
154
165
  });
155
166
  }
156
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
167
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
157
168
  });
158
169
  });
159
170
  }
171
+ else {
172
+ messages.push('\n>>>>>>群组微博订阅<<<<<<\n当前没有任何群组订阅数据~');
173
+ }
160
174
  // 处理私聊订阅
161
175
  if (subData.private && Object.keys(subData.private).length > 0) {
162
- messages.push('------私聊微博订阅------');
176
+ messages.push('\n>>>>>>私聊微博订阅<<<<<<');
163
177
  Object.keys(subData.private).forEach(userId => {
164
- messages.push(`用户ID:${userId}:`);
178
+ messages.push(`\n<用户${userId}>:`);
165
179
  subData.private[userId].forEach((item) => {
166
180
  const types = new Set();
167
181
  if (item.type && item.type.length) {
@@ -171,16 +185,30 @@ message.use(async (e) => {
171
185
  }
172
186
  });
173
187
  }
174
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
188
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
175
189
  });
176
190
  });
177
191
  }
192
+ else {
193
+ messages.push('\n>>>>>>私聊微博订阅<<<<<<\n当前没有任何私聊订阅数据~');
194
+ }
178
195
  e.reply(`推送列表如下:\n${messages.join('\n')}`);
179
196
  }
180
197
  }, [/^(#|\/)(yuki|优纪)?(微博|weibo|WEIBO)全部(推送|动态|订阅)列表$/]);
181
198
  /** 单独群聊或私聊的订阅的b站推送列表 */
182
199
  message.use(async (e) => {
183
200
  let subData = weiboPushData || { group: {}, private: {} };
201
+ // 如果聊天ID没有订阅数据,则删除该聊天ID
202
+ for (let chatType in subData) {
203
+ if (subData.hasOwnProperty(chatType)) {
204
+ subData[chatType] = Object.keys(subData[chatType]).reduce((nonEmptyData, chatId) => {
205
+ if (subData[chatType][chatId].length > 0) {
206
+ nonEmptyData[chatId] = subData[chatType][chatId];
207
+ }
208
+ return nonEmptyData;
209
+ }, {});
210
+ }
211
+ }
184
212
  const messages = [];
185
213
  const typeMap = {
186
214
  DYNAMIC_TYPE_AV: '视频',
@@ -204,7 +232,7 @@ message.use(async (e) => {
204
232
  }
205
233
  });
206
234
  }
207
- messages.push(`${item.name}:${item.uid} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
235
+ messages.push(`${item.uid}:${item.name} ${types.size ? `[${Array.from(types).join('、')}]` : ' [全部动态]'}`);
208
236
  });
209
237
  e.reply(`推送列表如下:\n${messages.join('\n')}`);
210
238
  }, [/^(#|\/)(yuki|优纪)?(微博|weibo|WEIBO)(推送|动态|订阅)列表$/]);
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { BOT_NAME, ConfigController } from 'yunzaijs';
2
+ import { ConfigController, BOT_NAME } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { createRequire, _paths } from '../../utils/paths.js';
5
+ import { _paths, createRequire } from '../../utils/paths.js';
6
6
 
7
7
  // Footer.tsx
8
8
  const require = createRequire(import.meta.url);
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { BOT_NAME, ConfigController } from 'yunzaijs';
2
+ import { ConfigController, BOT_NAME } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { createRequire, _paths } from '../../utils/paths.js';
5
+ import { _paths, createRequire } from '../../utils/paths.js';
6
6
 
7
7
  //help.tsx
8
8
  const require = createRequire(import.meta.url);
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { BOT_NAME, ConfigController } from 'yunzaijs';
2
+ import { ConfigController, BOT_NAME } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { createRequire, _paths } from '../../utils/paths.js';
5
+ import { _paths, createRequire } from '../../utils/paths.js';
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
8
  const botVersion = ConfigController.package?.version;
@@ -102,42 +102,28 @@ class BiliQuery {
102
102
  formatData.data.title = desc?.title;
103
103
  additional = data?.modules?.module_dynamic?.additional;
104
104
  // 文章内容过长,则尝试获取全文
105
+ let content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional) || '';
105
106
  if (String(desc?.summary?.text).length >= 480) {
106
107
  const fullArticleContent = await this.getFullArticleContent(this.formatUrl(desc?.jump_url));
107
108
  if (fullArticleContent) {
108
109
  const { readInfo, articleType } = fullArticleContent;
109
- // 文章链接类型为 cv(旧类型) 或者 opus(新类型)
110
- if (articleType === 'cv') {
111
- formatData.data.content = this.praseFullOldTypeArticleContent(readInfo?.content);
112
- if (String(formatData.data.content).length < 100) {
113
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional) || '';
114
- formatData.data.pics = pics;
115
- }
116
- else {
117
- formatData.data.pics = [];
110
+ // 文章类型为 cv(旧类型) 或者 opus(新类型)
111
+ if (articleType === 'opus') {
112
+ const newTypeContent = this.praseFullNewTypeArticleContent(readInfo?.paragraphs);
113
+ if (newTypeContent) {
114
+ content = newTypeContent.content || content;
115
+ pics = newTypeContent.img && newTypeContent.img.length > 0 ? newTypeContent.img : pics;
118
116
  }
119
117
  }
120
- else if (articleType === 'opus') {
121
- const FullNewTypeArticleContent = this.praseFullNewTypeArticleContent(readInfo?.paragraphs);
122
- if (FullNewTypeArticleContent) {
123
- const { content, img } = FullNewTypeArticleContent;
124
- formatData.data.content = content;
125
- formatData.data.pics = img && img.length > 0 ? img : pics;
126
- if (content && content.length < 100) {
127
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional);
128
- }
129
- }
130
- }
131
- else {
132
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional) || '';
133
- formatData.data.pics = pics;
118
+ else if (articleType === 'cv') {
119
+ const oldTypeContent = this.praseFullOldTypeArticleContent(readInfo?.content);
120
+ content = oldTypeContent || content;
134
121
  }
122
+ content = String(content).length < 100 ? this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional) : content;
135
123
  }
136
124
  }
137
- else {
138
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text, additional) || '';
139
- formatData.data.pics = pics;
140
- }
125
+ formatData.data.content = content;
126
+ formatData.data.pics = pics;
141
127
  }
142
128
  else if (majorType === 'MAJOR_TYPE_ARTICLE') {
143
129
  desc = data?.modules?.module_dynamic?.major?.article || {};
@@ -251,7 +237,7 @@ class BiliQuery {
251
237
  };
252
238
  /**获取完整B站文章内容
253
239
  * @param postUrl - 文章链接: https://www.bilibili.com/read/cvxxxx 或者 https://www.bilibili.com/opus/xxxx
254
- * @returns {JSON} 完整的B站文章内容json数据
240
+ * @returns 完整的B站文章内容json数据
255
241
  */
256
242
  static async getFullArticleContent(postUrl) {
257
243
  let { cookie } = await readSyncCookie();
@@ -262,24 +248,22 @@ class BiliQuery {
262
248
  responseType: 'text'
263
249
  });
264
250
  const text = response.data;
265
- let match, readInfo, articleType;
266
- if (/^https:\/\/www.bilibili.com\/read\/cv/.test(postUrl)) {
267
- match = String(text).match(/"readInfo":([\s\S]+?),"readViewInfo":/);
268
- if (match) {
269
- const full_json_text = match[1];
270
- readInfo = JSON.parse(full_json_text);
271
- articleType = 'cv';
272
- return { readInfo, articleType };
273
- }
251
+ let matchCV, matchOPUS, readInfo, articleType;
252
+ matchCV = String(text).match(/"readInfo":([\s\S]+?),"readViewInfo":/);
253
+ matchOPUS = String(text).match(/"module_content"\s*:\s*([\s\S]+?)\s*,\s*"module_type"\s*:\s*"MODULE_TYPE_CONTENT"/);
254
+ if (matchOPUS) {
255
+ logger.info(`文章内容新`);
256
+ const full_json_text = matchOPUS[1];
257
+ readInfo = JSON.parse(full_json_text);
258
+ articleType = 'opus';
259
+ return { readInfo, articleType };
274
260
  }
275
- else if (/^https:\/\/www.bilibili.com\/opus\//.test(postUrl)) {
276
- match = String(text).match(/"module_content":([\s\S]+?),\s*"module_type":"MODULE_TYPE_CONTENT"/);
277
- if (match) {
278
- const full_json_text = match[1];
279
- readInfo = JSON.parse(full_json_text);
280
- articleType = 'opus';
281
- return { readInfo, articleType };
282
- }
261
+ else if (matchCV) {
262
+ logger.info(`文章内容旧`);
263
+ const full_json_text = matchCV[1];
264
+ readInfo = JSON.parse(full_json_text);
265
+ articleType = 'cv';
266
+ return { readInfo, articleType };
283
267
  }
284
268
  }
285
269
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.7-12",
3
+ "version": "2.0.7-14",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",