karin-plugin-kkk 1.0.5 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.7](https://github.com/ikenxuan/karin-plugin-kkk/compare/v1.0.6...v1.0.7) (2025-01-30)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 抖音推送图集解析 ([0ccc71a](https://github.com/ikenxuan/karin-plugin-kkk/commit/0ccc71a0bdb2e302a00a28bc9bbeeee415af4dba))
9
+ * 移除无用导入 ([3a3aac3](https://github.com/ikenxuan/karin-plugin-kkk/commit/3a3aac37291dae65cad66f0a9fc80850ad95c265))
10
+
11
+ ## [1.0.6](https://github.com/ikenxuan/karin-plugin-kkk/compare/v1.0.5...v1.0.6) (2025-01-21)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **bilibili/douyin:** 优化用户列表渲染逻辑 ([dde7ee0](https://github.com/ikenxuan/karin-plugin-kkk/commit/dde7ee04d1f209d6da15ae06fe5e6590fae1bb1a))
17
+ * 移除无用导入 ([3a3aac3](https://github.com/ikenxuan/karin-plugin-kkk/commit/3a3aac37291dae65cad66f0a9fc80850ad95c265))
18
+
3
19
  ## [1.0.5](https://github.com/ikenxuan/karin-plugin-kkk/compare/v1.0.4...v1.0.5) (2025-01-20)
4
20
 
5
21
 
package/README.md CHANGED
@@ -88,19 +88,17 @@ git clone https://github.com/你的GitHub用户名/karin-plugin-kkk.git
88
88
  ```sh
89
89
  cd karin-plugin-kkk/
90
90
  ```
91
- 4. 安装依赖
91
+ 4. 初始化开发环境
92
+ ```sh
93
+ pnpm run init
94
+ ```
95
+ 5. 安装依赖
92
96
  ```sh
93
97
  pnpm install
94
98
  ```
95
- 5. 启动开发环境
96
-
97
- 两条命令任选一条执行
98
-
99
+ 6. 启动开发环境
99
100
  ```sh
100
- # 自动重载 apps 目录下的所有文件
101
- pnpm ts
102
- # 保存 src 目录下的文件后自动重启
103
- pnpm watch
101
+ pnpm dev
104
102
  ```
105
103
  </details>
106
104
 
package/lib/apps/admin.js CHANGED
@@ -36,30 +36,29 @@ export const setbilick = karin.command(/^#?(kkk)?s*设置s*(B站)ck$/i, async (e
36
36
  await e.reply('设置成功!', { at: true });
37
37
  return true;
38
38
  }, { perm: 'master', name: 'kkk-ck管理', event: 'message.friend' });
39
- const authFailMsg = '你暂时没有这个权限使用这个功能啦 ~ 只有主人可以使用哦';
40
39
  // 插件类
41
40
  export class Admin extends Plugin {
42
41
  constructor() {
43
42
  super({
44
43
  name: 'kkk-管理',
45
44
  rule: [
46
- { reg: createSwitchRegExp('app'), fnc: 'ConfigSwitch', permission: 'master', authFailMsg },
47
- { reg: createNumberRegExp('app'), fnc: 'ConfigNumber', permission: 'master', authFailMsg },
48
- { reg: createCustomRegExp('app'), fnc: 'ConfigCustom', permission: 'master', authFailMsg },
49
- { reg: createSwitchRegExp('douyin'), fnc: 'ConfigSwitch', permission: 'master', authFailMsg },
50
- { reg: createNumberRegExp('douyin'), fnc: 'ConfigNumber', permission: 'master', authFailMsg },
51
- { reg: createNumberRegExp('douyin'), fnc: 'ConfigCustom', permission: 'master', authFailMsg },
52
- { reg: createSwitchRegExp('bilibili'), fnc: 'ConfigSwitch', permission: 'master', authFailMsg },
53
- { reg: createNumberRegExp('bilibili'), fnc: 'ConfigNumber', permission: 'master', authFailMsg },
54
- { reg: createNumberRegExp('bilibili'), fnc: 'ConfigCustom', permission: 'master', authFailMsg },
55
- { reg: createSwitchRegExp('upload'), fnc: 'ConfigSwitch', permission: 'master', authFailMsg },
56
- { reg: createNumberRegExp('upload'), fnc: 'ConfigNumber', permission: 'master', authFailMsg },
57
- { reg: createNumberRegExp('upload'), fnc: 'ConfigCustom', permission: 'master', authFailMsg },
58
- { reg: createSwitchRegExp('kuaishou'), fnc: 'ConfigSwitch', permission: 'master', authFailMsg },
59
- { reg: createNumberRegExp('kuaishou'), fnc: 'ConfigNumber', permission: 'master', authFailMsg },
60
- { reg: createNumberRegExp('kuaishou'), fnc: 'ConfigCustom', permission: 'master', authFailMsg },
61
- { reg: /^#kkk设置$/, fnc: 'index_Settings', permission: 'master', authFailMsg },
62
- { reg: /^#?kkk删除缓存$/, fnc: 'deleteCache', permission: 'master', authFailMsg }
45
+ { reg: createSwitchRegExp('app'), fnc: 'ConfigSwitch', permission: 'master' },
46
+ { reg: createNumberRegExp('app'), fnc: 'ConfigNumber', permission: 'master' },
47
+ { reg: createCustomRegExp('app'), fnc: 'ConfigCustom', permission: 'master' },
48
+ { reg: createSwitchRegExp('douyin'), fnc: 'ConfigSwitch', permission: 'master' },
49
+ { reg: createNumberRegExp('douyin'), fnc: 'ConfigNumber', permission: 'master' },
50
+ { reg: createNumberRegExp('douyin'), fnc: 'ConfigCustom', permission: 'master' },
51
+ { reg: createSwitchRegExp('bilibili'), fnc: 'ConfigSwitch', permission: 'master' },
52
+ { reg: createNumberRegExp('bilibili'), fnc: 'ConfigNumber', permission: 'master' },
53
+ { reg: createNumberRegExp('bilibili'), fnc: 'ConfigCustom', permission: 'master' },
54
+ { reg: createSwitchRegExp('upload'), fnc: 'ConfigSwitch', permission: 'master' },
55
+ { reg: createNumberRegExp('upload'), fnc: 'ConfigNumber', permission: 'master' },
56
+ { reg: createNumberRegExp('upload'), fnc: 'ConfigCustom', permission: 'master' },
57
+ { reg: createSwitchRegExp('kuaishou'), fnc: 'ConfigSwitch', permission: 'master' },
58
+ { reg: createNumberRegExp('kuaishou'), fnc: 'ConfigNumber', permission: 'master' },
59
+ { reg: createNumberRegExp('kuaishou'), fnc: 'ConfigCustom', permission: 'master' },
60
+ { reg: /^#kkk设置$/, fnc: 'index_Settings', permission: 'master' },
61
+ { reg: /^#?kkk删除缓存$/, fnc: 'deleteCache', permission: 'master' }
63
62
  ]
64
63
  });
65
64
  }
@@ -29,7 +29,7 @@ export declare class Networks {
29
29
  getfetch(): Promise<AxiosResponse | boolean>;
30
30
  returnResult(): Promise<AxiosResponse>;
31
31
  /** 最终地址(跟随重定向) */
32
- getLongLink(): Promise<string>;
32
+ getLongLink(url?: string): Promise<string>;
33
33
  /** 获取首个302链接 */
34
34
  getLocation(): Promise<AxiosResponse['headers']['location']>;
35
35
  /** 获取数据并处理数据的格式化,默认json */
@@ -156,19 +156,20 @@ export class Networks {
156
156
  return response;
157
157
  }
158
158
  /** 最终地址(跟随重定向) */
159
- async getLongLink() {
159
+ async getLongLink(url = '') {
160
160
  try {
161
- const response = await this.axiosInstance({
162
- method: 'GET',
163
- url: this.url
164
- });
165
- return response.request.res.responseUrl; // axios中获取最终的请求URL
161
+ const response = await this.axiosInstance.get(this.url || url);
162
+ return response.request.res.responseUrl;
166
163
  }
167
164
  catch (error) {
168
- if (error instanceof AxiosError) {
169
- throw new Error(error.stack);
165
+ const axiosError = error;
166
+ if (axiosError.response && axiosError.response.status === 302) {
167
+ // 获取重定向地址
168
+ const redirectUrl = axiosError.response.headers.location;
169
+ // 递归调用,直到获取最终地址
170
+ return this.getLongLink(redirectUrl);
170
171
  }
171
- return '';
172
+ throw error;
172
173
  }
173
174
  }
174
175
  /** 获取首个302链接 */
@@ -81,9 +81,8 @@ export declare class Bilibilipush extends Base {
81
81
  /**
82
82
  * 渲染推送列表图片
83
83
  * @param pushList B站配置文件的推送列表
84
- * @param host_mid 优先展示的UP主的UID
85
84
  * @returns
86
85
  */
87
- renderPushList(pushList: bilibiliPushItem[], host_mid?: string): Promise<true | undefined>;
86
+ renderPushList(pushList: bilibiliPushItem[]): Promise<void>;
88
87
  }
89
88
  export {};
@@ -536,7 +536,7 @@ export class Bilibilipush extends Base {
536
536
  await this.e.reply('请发送「#kkk设置B站推送开启」以进行推送');
537
537
  logger.info(`\n设置成功!${data.data.card.name}\nUID:${host_mid}`);
538
538
  // 渲染状态图片
539
- await this.renderPushList(config.bilibili, host_mid);
539
+ await this.renderPushList(config.bilibili);
540
540
  }
541
541
  }
542
542
  else {
@@ -550,7 +550,7 @@ export class Bilibilipush extends Base {
550
550
  if (Config.bilibili.push.switch === false)
551
551
  await this.e.reply('请发送「#kkk设置B站推送开启」以进行推送');
552
552
  // 渲染状态图片
553
- await this.renderPushList(config.bilibili, host_mid);
553
+ await this.renderPushList(config.bilibili);
554
554
  }
555
555
  // 更新配置文件
556
556
  Config.Modify('pushlist', 'bilibili', config.bilibili);
@@ -605,35 +605,28 @@ export class Bilibilipush extends Base {
605
605
  /**
606
606
  * 渲染推送列表图片
607
607
  * @param pushList B站配置文件的推送列表
608
- * @param host_mid 优先展示的UP主的UID
609
608
  * @returns
610
609
  */
611
- async renderPushList(pushList, host_mid) {
610
+ async renderPushList(pushList) {
612
611
  const groupInfo = await this.e.bot.getGroupInfo('groupId' in this.e && this.e.groupId ? this.e.groupId : '');
612
+ /** 排除出有e.groupId的推送用户 */
613
613
  const filteredList = pushList.filter(item => item.group_id.some(group => group.split(':')[0] === groupInfo.groupId));
614
614
  if (filteredList.length === 0) {
615
615
  await this.e.reply(`当前群:${groupInfo.groupName}(${groupInfo.groupId})\n没有设置任何B站UP推送!\n可使用「#设置B站推送 + UP主UID」进行设置`);
616
- return true;
617
616
  }
618
617
  /** 用户的今日动态列表 */
619
- const DynamicList = await this.getDynamicList(filteredList);
620
618
  const renderOpt = [];
621
- for (const dynamic_id in removeDuplicateHostMid(DynamicList.willbepushlist)) {
622
- const item = DynamicList.willbepushlist[dynamic_id];
619
+ for (const item of filteredList) {
623
620
  const userInfo = await getBilibiliData('用户主页数据', Config.cookies.bilibili, { host_mid: item.host_mid });
624
621
  renderOpt.push({
625
622
  avatar_img: userInfo.data.card.face,
626
623
  username: userInfo.data.card.name,
627
- host_mid: host_mid ?? userInfo.data.card.mid,
624
+ host_mid: userInfo.data.card.mid,
628
625
  fans: this.count(userInfo.data.follower),
629
626
  total_favorited: this.count(userInfo.data.like_num),
630
- following_count: this.count(userInfo.data.card.attention),
631
- willPushNum: 999
627
+ following_count: this.count(userInfo.data.card.attention)
632
628
  });
633
629
  }
634
- // 将此次设置推送的用户排序到首位
635
- if (host_mid)
636
- renderOpt.sort((a, b) => (a.host_mid === host_mid ? -1 : b.host_mid === host_mid ? 1 : 0));
637
630
  const img = await Render('bilibili/userlist', { renderOpt });
638
631
  await this.e.reply(img);
639
632
  }
@@ -698,15 +691,3 @@ const skipDynamic = (Dynamic_Data) => {
698
691
  }
699
692
  return false;
700
693
  };
701
- const removeDuplicateHostMid = (willBePushList) => {
702
- const result = {};
703
- const seenHostMids = new Set();
704
- for (const key in willBePushList) {
705
- const item = willBePushList[key];
706
- if (!seenHostMids.has(item.host_mid)) {
707
- result[key] = item;
708
- seenHostMids.add(item.host_mid);
709
- }
710
- }
711
- return result;
712
- };
@@ -7,7 +7,12 @@ import { Networks } from '../../module/utils/index.js';
7
7
  * @returns
8
8
  */
9
9
  export async function getDouyinID(url, log = true) {
10
- const longLink = await new Networks({ url }).getLongLink();
10
+ const longLink = await new Networks({
11
+ url,
12
+ headers: {
13
+ 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
14
+ }
15
+ }).getLongLink();
11
16
  let result = {};
12
17
  switch (true) {
13
18
  case /https:\/\/(?:www\.iesdouyin\.com)\/share\/slides/.test(longLink):
@@ -69,6 +69,11 @@ export declare class DouYinpush extends Base {
69
69
  * @returns 操作成功或失败的消息字符串。
70
70
  */
71
71
  setting(data: any): Promise<void>;
72
- renderPushList(pushList: douyinPushItem[], short_id?: string): Promise<true | undefined>;
72
+ /**
73
+ * 渲染推送列表图片
74
+ * @param pushList 抖音推送列表
75
+ * @returns
76
+ */
77
+ renderPushList(pushList: douyinPushItem[]): Promise<void>;
73
78
  }
74
79
  export {};
@@ -130,7 +130,7 @@ export class DouYinpush extends Base {
130
130
  else if (!iddata.is_mp4 && iddata.type === 'one_work') { // 如果新作品是图集
131
131
  const imageres = [];
132
132
  let image_url;
133
- for (const item of Detail_Data.aweme_detail.images) {
133
+ for (const item of Detail_Data.images) {
134
134
  image_url = item.url_list[2] || item.url_list[1]; // 图片地址
135
135
  imageres.push(segment.image(image_url));
136
136
  }
@@ -496,7 +496,7 @@ export class DouYinpush extends Base {
496
496
  await this.e.reply('请发送「#kkk设置B站推送开启」以进行推送');
497
497
  logger.info(`\n设置成功!${UserInfoData.user.nickname}\n抖音号:${user_shortid}\nsec_uid${UserInfoData.user.sec_uid}`);
498
498
  // 渲染状态图片
499
- await this.renderPushList(config.douyin, user_shortid);
499
+ await this.renderPushList(config.douyin);
500
500
  }
501
501
  }
502
502
  else {
@@ -510,7 +510,7 @@ export class DouYinpush extends Base {
510
510
  if (Config.douyin.push.switch === false)
511
511
  await this.e.reply('请发送「#kkk设置B站推送开启」以进行推送');
512
512
  // 渲染状态图片
513
- await this.renderPushList(config.douyin, user_shortid);
513
+ await this.renderPushList(config.douyin);
514
514
  }
515
515
  Config.Modify('pushlist', 'douyin', config.douyin);
516
516
  }
@@ -518,18 +518,20 @@ export class DouYinpush extends Base {
518
518
  logger.error(error);
519
519
  }
520
520
  }
521
- async renderPushList(pushList, short_id) {
521
+ /**
522
+ * 渲染推送列表图片
523
+ * @param pushList 抖音推送列表
524
+ * @returns
525
+ */
526
+ async renderPushList(pushList) {
522
527
  const groupInfo = await this.e.bot.getGroupInfo('groupId' in this.e && this.e.groupId ? this.e.groupId : '');
528
+ /** 排除出有e.groupId的推送用户 */
523
529
  const filteredList = pushList.filter(item => item.group_id.some(group => group.split(':')[0] === groupInfo.groupId));
524
530
  if (filteredList.length === 0) {
525
531
  await this.e.reply(`当前群:${groupInfo.groupName}(${groupInfo.groupId})\n没有设置任何抖音博主推送!\n可使用「#设置抖音推送 + 抖音号」进行设置`);
526
- return true;
527
532
  }
528
- /** 用户的今日动态列表 */
529
- const DynamicList = await this.getDynamicList(filteredList);
530
533
  const renderOpt = [];
531
- for (const dynamic_id in removeDuplicateHostMid(DynamicList.willbepushlist)) {
532
- const item = DynamicList.willbepushlist[dynamic_id];
534
+ for (const item of filteredList) {
533
535
  const userInfo = await getDouyinData('用户主页数据', Config.cookies.douyin, { sec_uid: item.sec_uid });
534
536
  renderOpt.push({
535
537
  avatar_img: userInfo.user.avatar_larger.url_list[0],
@@ -537,13 +539,9 @@ export class DouYinpush extends Base {
537
539
  short_id: userInfo.user.unique_id === '' ? userInfo.user.short_id : userInfo.user.unique_id,
538
540
  fans: this.count(userInfo.user.follower_count),
539
541
  total_favorited: this.count(userInfo.user.total_favorited),
540
- following_count: this.count(userInfo.user.following_count),
541
- willPushNum: 999
542
+ following_count: this.count(userInfo.user.following_count)
542
543
  });
543
544
  }
544
- // 将此次设置推送的用户排序到首位
545
- if (short_id)
546
- renderOpt.sort((a, b) => (a.short_id === short_id ? -1 : b.short_id === short_id ? 1 : 0));
547
545
  const img = await Render('douyin/userlist', { renderOpt });
548
546
  await this.e.reply(img);
549
547
  }
@@ -631,15 +629,3 @@ const findMatchingSecUid = (DBdata, secUidToCheck) => {
631
629
  }
632
630
  return '';
633
631
  };
634
- const removeDuplicateHostMid = (willBePushList) => {
635
- const result = {};
636
- const seenHostMids = new Set();
637
- for (const key in willBePushList) {
638
- const item = willBePushList[key];
639
- if (!seenHostMids.has(item.sec_uid)) {
640
- result[key] = item;
641
- seenHostMids.add(item.sec_uid);
642
- }
643
- }
644
- return result;
645
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karin-plugin-kkk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "a Karin video parsing tool",
5
5
  "keywords": [
6
6
  "karin-plugin",
@@ -36,18 +36,9 @@
36
36
  "pub": "npm publish --access public",
37
37
  "pub-beta": "npm publish --tag beta",
38
38
  "sort": "npx sort-package-json",
39
- "karin": "karin",
40
- "app": "karin app",
41
39
  "start": "karin start",
42
- "pm2": "karin pm2",
43
- "stop": "karin stop",
44
- "rs": "karin rs",
45
- "log": "karin log",
46
- "up": "karin up",
47
40
  "init": "karin init",
48
- "dev": "tsx watch --include \"src/**/*.ts\" src/index.ts",
49
- "ts": "karin ts",
50
- "watch": "karin watch"
41
+ "dev": "tsx watch --include \"src/**/*.ts\" src/index.ts"
51
42
  },
52
43
  "dependencies": {
53
44
  "@ikenxuan/amagi": "4.2.5",
@@ -17,11 +17,6 @@
17
17
  <span>关注: {{val.following_count}}</span>
18
18
  </div>
19
19
  </div>
20
- <!-- {{if val.willPushNum > 0}}
21
- <span class="pending-push active">待推送: {{val.willPushNum}}</span>
22
- {{else}}
23
- <span class="pending-push inactive">待推送: {{val.willPushNum}}</span>
24
- {{/if}} -->
25
20
  </div>
26
21
  </li>
27
22
  <div style="height: 40px;"></div>
@@ -11,7 +11,7 @@
11
11
  <div class="user-details">
12
12
  <span class="user-name">{{val.username}}</span>
13
13
  <div class="user-stats">
14
- <span>UID: {{val.short_id}}</span>
14
+ <span>抖音号: {{val.short_id}}</span>
15
15
  <span>粉丝: {{val.fans}}</span>
16
16
  <span>获赞: {{val.total_favorited}}</span>
17
17
  <span>关注: {{val.following_count}}</span>