koishi-plugin-bilitester 1.3.0 → 1.4.1

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/lib/index.js CHANGED
@@ -291,7 +291,7 @@ function apply(ctx, config) {
291
291
  }
292
292
  };
293
293
  const cmd = ctx.command('bilitester', '哔哩哔哩登录和API调用');
294
- cmd.subcommand('login', '获取哔哩哔哩登录二维码')
294
+ cmd.subcommand('.login', '获取哔哩哔哩登录二维码')
295
295
  .action(async ({ session }) => {
296
296
  if (!session) {
297
297
  return '无法获取会话信息';
@@ -335,7 +335,7 @@ function apply(ctx, config) {
335
335
  return '获取二维码失败,请稍后重试';
336
336
  }
337
337
  });
338
- cmd.subcommand('logout', '退出哔哩哔哩登录')
338
+ cmd.subcommand('.logout', '退出哔哩哔哩登录')
339
339
  .action(async ({ session }) => {
340
340
  if (!session) {
341
341
  return '无法获取会话信息';
@@ -350,7 +350,7 @@ function apply(ctx, config) {
350
350
  return '退出登录失败,请稍后重试';
351
351
  }
352
352
  });
353
- cmd.subcommand('info', '查看当前登录的哔哩哔哩账号信息')
353
+ cmd.subcommand('.info', '查看当前登录的哔哩哔哩账号信息')
354
354
  .action(async ({ session }) => {
355
355
  if (!session) {
356
356
  return '无法获取会话信息';
@@ -378,7 +378,7 @@ function apply(ctx, config) {
378
378
  return '获取账号信息失败,请稍后重试';
379
379
  }
380
380
  });
381
- cmd.subcommand('refresh', '刷新账号信息')
381
+ cmd.subcommand('.refresh', '刷新账号信息')
382
382
  .action(async ({ session }) => {
383
383
  if (!session) {
384
384
  return '无法获取会话信息';
@@ -417,7 +417,7 @@ function apply(ctx, config) {
417
417
  return '刷新账号信息失败,请稍后重试';
418
418
  }
419
419
  });
420
- cmd.subcommand('video <bvid>', '获取B站视频信息')
420
+ cmd.subcommand('.video <bvid>', '获取B站视频信息')
421
421
  .action(async ({ session }, bvid) => {
422
422
  if (!session) {
423
423
  return '无法获取会话信息';
@@ -455,7 +455,7 @@ function apply(ctx, config) {
455
455
  return '获取视频信息失败,请稍后重试';
456
456
  }
457
457
  });
458
- cmd.subcommand('parse <link>', '解析B站视频链接')
458
+ cmd.subcommand('.parse <link>', '解析B站视频链接')
459
459
  .action(async ({ session }, link) => {
460
460
  if (!session) {
461
461
  return '无法获取会话信息';
@@ -519,7 +519,7 @@ function apply(ctx, config) {
519
519
  return '解析视频链接失败,请稍后重试';
520
520
  }
521
521
  });
522
- cmd.subcommand('dynamic', '获取哔哩哔哩动态')
522
+ cmd.subcommand('.dynamic', '获取哔哩哔哩动态')
523
523
  .action(async ({ session }) => {
524
524
  if (!session) {
525
525
  return '无法获取会话信息';
@@ -570,7 +570,7 @@ function apply(ctx, config) {
570
570
  return '获取动态失败,请稍后重试';
571
571
  }
572
572
  });
573
- cmd.subcommand('live <roomId>', '获取B站直播间信息')
573
+ cmd.subcommand('.live <roomId>', '获取B站直播间信息')
574
574
  .action(async ({ session }, roomId) => {
575
575
  if (!session) {
576
576
  return '无法获取会话信息';
@@ -608,7 +608,7 @@ function apply(ctx, config) {
608
608
  return '获取直播间信息失败,请稍后重试';
609
609
  }
610
610
  });
611
- cmd.subcommand('search <keyword>', '搜索B站视频')
611
+ cmd.subcommand('.search <keyword>', '搜索B站视频')
612
612
  .action(async ({ session }, keyword) => {
613
613
  if (!session) {
614
614
  return '无法获取会话信息';
@@ -674,7 +674,7 @@ function apply(ctx, config) {
674
674
  return '搜索视频失败,请稍后重试';
675
675
  }
676
676
  });
677
- cmd.subcommand('select <index>', '选择搜索结果中的视频')
677
+ cmd.subcommand('.select <index>', '选择搜索结果中的视频')
678
678
  .action(async ({ session }, index) => {
679
679
  if (!session) {
680
680
  return '无法获取会话信息';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilitester",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "哔哩哔哩登录和API调用插件,支持二维码登录和Cookie管理",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -1,43 +0,0 @@
1
- export interface QRCodeResponse {
2
- code: number;
3
- message: string;
4
- ttl: number;
5
- data: {
6
- url: string;
7
- qrcode_key: string;
8
- };
9
- }
10
- export interface PollResponse {
11
- code: number;
12
- message: string;
13
- ttl: number;
14
- data: {
15
- url: string;
16
- refresh_token: string;
17
- timestamp: number;
18
- code: number;
19
- message: string;
20
- };
21
- }
22
- export interface LoginResult {
23
- success: boolean;
24
- sessdata?: string;
25
- biliJct?: string;
26
- dedeUserId?: string;
27
- dedeUserIdCkMd5?: string;
28
- }
29
- export interface LoginSession {
30
- qrcodeKey: string;
31
- userId: string;
32
- startTime: number;
33
- }
34
- export declare class AuthService {
35
- private static readonly POLL_INTERVAL;
36
- private static readonly QR_CODE_TIMEOUT;
37
- static generateQRCode(): Promise<{
38
- url: string;
39
- qrcodeKey: string;
40
- } | null>;
41
- static pollLoginStatus(qrcodeKey: string, onLogin: (result: LoginResult) => void, onTimeout: () => void, onError: (error: string) => void): Promise<NodeJS.Timeout>;
42
- static getCookieString(sessdata: string, biliJct: string, dedeUserId: string, dedeUserIdCkMd5: string): string;
43
- }
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AuthService = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class AuthService {
9
- static async generateQRCode() {
10
- try {
11
- const response = await axios_1.default.get('https://passport.bilibili.com/x/passport-login/web/qrcode/generate', {
12
- headers: {
13
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
14
- },
15
- });
16
- const { code, data } = response.data;
17
- if (code === 0 && data) {
18
- return {
19
- url: data.url,
20
- qrcodeKey: data.qrcode_key,
21
- };
22
- }
23
- return null;
24
- }
25
- catch (error) {
26
- console.error('生成二维码失败:', error);
27
- return null;
28
- }
29
- }
30
- static async pollLoginStatus(qrcodeKey, onLogin, onTimeout, onError) {
31
- return new Promise((resolve) => {
32
- const timer = setInterval(async () => {
33
- try {
34
- const response = await axios_1.default.get('https://passport.bilibili.com/x/passport-login/web/qrcode/poll', {
35
- params: { qrcode_key: qrcodeKey },
36
- headers: {
37
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
38
- },
39
- });
40
- const { code, data } = response.data;
41
- if (code === 0) {
42
- if (data.code === 0) {
43
- const cookies = response.headers['set-cookie'] || [];
44
- let sessdata = '';
45
- let biliJct = '';
46
- let dedeUserId = '';
47
- let dedeUserIdCkMd5 = '';
48
- for (const cookie of cookies) {
49
- if (cookie.includes('SESSDATA=')) {
50
- sessdata = cookie.match(/SESSDATA=([^;]+)/)?.[1] || '';
51
- }
52
- if (cookie.includes('bili_jct=')) {
53
- biliJct = cookie.match(/bili_jct=([^;]+)/)?.[1] || '';
54
- }
55
- if (cookie.includes('DedeUserID=')) {
56
- dedeUserId = cookie.match(/DedeUserID=([^;]+)/)?.[1] || '';
57
- }
58
- if (cookie.includes('DedeUserID__ckMd5=')) {
59
- dedeUserIdCkMd5 = cookie.match(/DedeUserID__ckMd5=([^;]+)/)?.[1] || '';
60
- }
61
- }
62
- if (sessdata && biliJct && dedeUserId) {
63
- onLogin({
64
- success: true,
65
- sessdata,
66
- biliJct,
67
- dedeUserId,
68
- dedeUserIdCkMd5,
69
- });
70
- clearInterval(timer);
71
- resolve(timer);
72
- }
73
- }
74
- else if (data.code === 86038) {
75
- onError('二维码已失效');
76
- clearInterval(timer);
77
- resolve(timer);
78
- }
79
- }
80
- }
81
- catch (error) {
82
- console.error('轮询登录状态失败:', error);
83
- onError('网络错误,请稍后重试');
84
- clearInterval(timer);
85
- resolve(timer);
86
- }
87
- }, this.POLL_INTERVAL);
88
- setTimeout(() => {
89
- clearInterval(timer);
90
- onTimeout();
91
- resolve(timer);
92
- }, this.QR_CODE_TIMEOUT * 1000);
93
- });
94
- }
95
- static getCookieString(sessdata, biliJct, dedeUserId, dedeUserIdCkMd5) {
96
- return `SESSDATA=${sessdata}; bili_jct=${biliJct}; DedeUserID=${dedeUserId}; DedeUserID__ckMd5=${dedeUserIdCkMd5}`;
97
- }
98
- }
99
- exports.AuthService = AuthService;
100
- AuthService.POLL_INTERVAL = 2000;
101
- AuthService.QR_CODE_TIMEOUT = 180;
@@ -1,98 +0,0 @@
1
- export interface VideoInfo {
2
- bvid: string;
3
- aid: number;
4
- title: string;
5
- desc: string;
6
- pic: string;
7
- owner: {
8
- mid: string;
9
- name: string;
10
- face: string;
11
- };
12
- stat: {
13
- view: number;
14
- danmaku: number;
15
- reply: number;
16
- favorite: number;
17
- coin: number;
18
- share: number;
19
- like: number;
20
- };
21
- duration: number;
22
- pubdate: number;
23
- }
24
- export interface VideoSearchResult {
25
- bvid: string;
26
- aid: number;
27
- title: string;
28
- pic: string;
29
- description: string;
30
- owner: {
31
- mid: string;
32
- name: string;
33
- face: string;
34
- };
35
- stat: {
36
- view: number;
37
- danmaku: number;
38
- reply: number;
39
- favorite: number;
40
- coin: number;
41
- share: number;
42
- like: number;
43
- };
44
- duration: number;
45
- pubdate: number;
46
- }
47
- export interface UserInfo {
48
- isLogin: boolean;
49
- mid: string;
50
- uname: string;
51
- face: string;
52
- vipStatus: number;
53
- vipType: number;
54
- vipDueDate: number;
55
- level_info: {
56
- current_level: number;
57
- current_exp: number;
58
- next_exp: string | number;
59
- };
60
- money: number;
61
- }
62
- export interface DynamicResponse {
63
- cards: Array<{
64
- card: string;
65
- desc: {
66
- type: number;
67
- dynamic_id: number;
68
- timestamp: number;
69
- };
70
- }>;
71
- }
72
- export interface LiveRoomInfo {
73
- roomid: number;
74
- uid: number;
75
- title: string;
76
- live_status: number;
77
- keyframe: string;
78
- cover: string;
79
- online: number;
80
- area_name: string;
81
- parent_area_name: string;
82
- }
83
- export interface SearchResponse {
84
- code: number;
85
- message: string;
86
- data: {
87
- result: VideoSearchResult[];
88
- };
89
- }
90
- export declare class BilibiliService {
91
- private axiosInstance;
92
- constructor(cookie: string);
93
- getUserInfo(): Promise<UserInfo | null>;
94
- getVideoInfo(bvid: string): Promise<VideoInfo | null>;
95
- searchVideos(keyword: string, page?: number): Promise<VideoSearchResult[] | null>;
96
- getDynamics(uid: string): Promise<DynamicResponse | null>;
97
- getLiveRoomInfo(roomId: number): Promise<LiveRoomInfo | null>;
98
- }
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BilibiliService = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class BilibiliService {
9
- constructor(cookie) {
10
- this.axiosInstance = axios_1.default.create({
11
- headers: {
12
- 'Cookie': cookie,
13
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
14
- 'Referer': 'https://www.bilibili.com',
15
- },
16
- });
17
- }
18
- async getUserInfo() {
19
- try {
20
- const response = await this.axiosInstance.get('https://api.bilibili.com/x/web-interface/nav');
21
- if (response.data.code === 0 && response.data.data.isLogin) {
22
- return response.data.data;
23
- }
24
- return null;
25
- }
26
- catch (error) {
27
- console.error('获取用户信息失败:', error);
28
- return null;
29
- }
30
- }
31
- async getVideoInfo(bvid) {
32
- try {
33
- const response = await this.axiosInstance.get('https://api.bilibili.com/x/web-interface/view', {
34
- params: { bvid }
35
- });
36
- if (response.data.code === 0) {
37
- return response.data.data;
38
- }
39
- return null;
40
- }
41
- catch (error) {
42
- console.error('获取视频信息失败:', error);
43
- return null;
44
- }
45
- }
46
- async searchVideos(keyword, page = 1) {
47
- try {
48
- const response = await this.axiosInstance.get('https://api.bilibili.com/x/web-interface/search/all', {
49
- params: {
50
- keyword,
51
- page,
52
- search_type: 'video',
53
- }
54
- });
55
- if (response.data.code === 0) {
56
- return response.data.data.result;
57
- }
58
- return null;
59
- }
60
- catch (error) {
61
- console.error('搜索视频失败:', error);
62
- return null;
63
- }
64
- }
65
- async getDynamics(uid) {
66
- try {
67
- const response = await this.axiosInstance.get('https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new', {
68
- params: {
69
- uid,
70
- type_list: '8',
71
- }
72
- });
73
- if (response.data.code === 0) {
74
- return response.data.data;
75
- }
76
- return null;
77
- }
78
- catch (error) {
79
- console.error('获取动态失败:', error);
80
- return null;
81
- }
82
- }
83
- async getLiveRoomInfo(roomId) {
84
- try {
85
- const response = await this.axiosInstance.get('https://api.live.bilibili.com/room/v1/Room/get_info', {
86
- params: { room_id: roomId }
87
- });
88
- if (response.data.code === 0) {
89
- return response.data.data;
90
- }
91
- return null;
92
- }
93
- catch (error) {
94
- console.error('获取直播间信息失败:', error);
95
- return null;
96
- }
97
- }
98
- }
99
- exports.BilibiliService = BilibiliService;
@@ -1,27 +0,0 @@
1
- import { Context } from 'koishi';
2
- export interface BilibiliAccount {
3
- id: number;
4
- userId: string;
5
- sessdata: string;
6
- biliJct: string;
7
- dedeUserId: string;
8
- dedeUserIdCkMd5: string;
9
- mid: string;
10
- name: string;
11
- face: string;
12
- vipStatus: number;
13
- vipType: number;
14
- vipDueDate: number;
15
- level: number;
16
- coins: number;
17
- createdAt: Date;
18
- updatedAt: Date;
19
- }
20
- export declare class DatabaseService {
21
- private ctx;
22
- constructor(ctx: Context);
23
- createAccount(account: Omit<BilibiliAccount, 'id'>): Promise<BilibiliAccount>;
24
- getAccountByUserId(userId: string): Promise<BilibiliAccount | null>;
25
- updateAccount(id: number, data: Partial<Omit<BilibiliAccount, 'id' | 'userId' | 'createdAt'>>): Promise<boolean>;
26
- deleteAccountByUserId(userId: string): Promise<boolean>;
27
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatabaseService = void 0;
4
- class DatabaseService {
5
- constructor(ctx) {
6
- this.ctx = ctx;
7
- this.ctx.model.extend('bilibili', {
8
- id: 'unsigned',
9
- userId: 'text',
10
- sessdata: 'text',
11
- biliJct: 'text',
12
- dedeUserId: 'text',
13
- dedeUserIdCkMd5: 'text',
14
- mid: 'text',
15
- name: 'text',
16
- face: 'text',
17
- vipStatus: 'integer',
18
- vipType: 'integer',
19
- vipDueDate: 'integer',
20
- level: 'integer',
21
- coins: 'float',
22
- createdAt: 'timestamp',
23
- updatedAt: 'timestamp',
24
- }, {
25
- autoInc: false,
26
- });
27
- }
28
- async createAccount(account) {
29
- const newAccount = {
30
- ...account,
31
- id: Date.now(),
32
- };
33
- await this.ctx.database.create('bilibili', newAccount);
34
- return newAccount;
35
- }
36
- async getAccountByUserId(userId) {
37
- const accounts = await this.ctx.database.get('bilibili', { userId });
38
- if (!accounts || accounts.length === 0) {
39
- return null;
40
- }
41
- return accounts[0];
42
- }
43
- async updateAccount(id, data) {
44
- try {
45
- await this.ctx.database.set('bilibili', { id }, {
46
- ...data,
47
- updatedAt: new Date(),
48
- });
49
- return true;
50
- }
51
- catch (error) {
52
- console.error('更新账号信息失败:', error);
53
- return false;
54
- }
55
- }
56
- async deleteAccountByUserId(userId) {
57
- try {
58
- await this.ctx.database.remove('bilibili', { userId });
59
- return true;
60
- }
61
- catch (error) {
62
- console.error('删除账号信息失败:', error);
63
- return false;
64
- }
65
- }
66
- }
67
- exports.DatabaseService = DatabaseService;