koishi-plugin-bilibili-notify 3.2.1-alpha.3 → 3.2.1-alpha.5
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/biliAPI.d.ts +2 -5
- package/lib/biliAPI.js +0 -53
- package/lib/blive.d.ts +1 -1
- package/lib/blive.js +20 -15
- package/lib/comRegister.js +28 -2
- package/package.json +9 -9
- package/readme.md +2 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Context, Schema, Service } from "koishi";
|
|
2
2
|
import { type AxiosInstance } from "axios";
|
|
3
3
|
import { CookieJar } from "tough-cookie";
|
|
4
4
|
import type { Notifier } from "@koishijs/plugin-notifier";
|
|
@@ -11,7 +11,6 @@ declare class BiliAPI extends Service {
|
|
|
11
11
|
static inject: string[];
|
|
12
12
|
jar: CookieJar;
|
|
13
13
|
client: AxiosInstance;
|
|
14
|
-
cacheable: any;
|
|
15
14
|
apiConfig: BiliAPI.Config;
|
|
16
15
|
loginData: any;
|
|
17
16
|
loginNotifier: Notifier;
|
|
@@ -19,8 +18,6 @@ declare class BiliAPI extends Service {
|
|
|
19
18
|
loginInfoIsLoaded: boolean;
|
|
20
19
|
constructor(ctx: Context, config: BiliAPI.Config);
|
|
21
20
|
protected start(): void | Promise<void>;
|
|
22
|
-
protected stop(): Awaitable<void>;
|
|
23
|
-
init(): Promise<void>;
|
|
24
21
|
getMixinKey: (orig: string) => string;
|
|
25
22
|
encWbi(params: {
|
|
26
23
|
[key: string]: string | number | object;
|
|
@@ -65,7 +62,7 @@ declare class BiliAPI extends Service {
|
|
|
65
62
|
cookies: any;
|
|
66
63
|
refresh_token: string;
|
|
67
64
|
}>;
|
|
68
|
-
getCSRF():
|
|
65
|
+
getCSRF(): string;
|
|
69
66
|
loadCookiesFromDatabase(): Promise<void>;
|
|
70
67
|
enableRefreshCookiesDetect(): void;
|
|
71
68
|
checkIfTokenNeedRefresh(refreshToken: string, csrf: string, times?: number): Promise<void>;
|
package/lib/biliAPI.js
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
10
|
};
|
|
@@ -45,8 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
12
|
const koishi_1 = require("koishi");
|
|
46
13
|
const md5_1 = __importDefault(require("md5"));
|
|
47
14
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
48
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
49
|
-
const node_https_1 = __importDefault(require("node:https"));
|
|
50
15
|
const axios_1 = __importDefault(require("axios"));
|
|
51
16
|
const tough_cookie_1 = require("tough-cookie");
|
|
52
17
|
const axios_cookiejar_support_1 = require("axios-cookiejar-support");
|
|
@@ -88,8 +53,6 @@ class BiliAPI extends koishi_1.Service {
|
|
|
88
53
|
static inject = ["database", "notifier"];
|
|
89
54
|
jar;
|
|
90
55
|
client;
|
|
91
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
92
|
-
cacheable;
|
|
93
56
|
apiConfig;
|
|
94
57
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
95
58
|
loginData;
|
|
@@ -101,27 +64,11 @@ class BiliAPI extends koishi_1.Service {
|
|
|
101
64
|
this.apiConfig = config;
|
|
102
65
|
}
|
|
103
66
|
start() {
|
|
104
|
-
// init
|
|
105
|
-
this.init();
|
|
106
67
|
// 创建新的http客户端(axios)
|
|
107
68
|
this.createNewClient();
|
|
108
69
|
// 从数据库加载cookies
|
|
109
70
|
this.loadCookiesFromDatabase();
|
|
110
71
|
}
|
|
111
|
-
stop() {
|
|
112
|
-
// 将DNS缓存卸载
|
|
113
|
-
this.cacheable.uninstall(node_http_1.default.globalAgent);
|
|
114
|
-
this.cacheable.uninstall(node_https_1.default.globalAgent);
|
|
115
|
-
}
|
|
116
|
-
async init() {
|
|
117
|
-
// 导入纯ESM模块Cacheable
|
|
118
|
-
const { default: CacheableLookup } = await Promise.resolve().then(() => __importStar(require("cacheable-lookup")));
|
|
119
|
-
// 创建Cacheable
|
|
120
|
-
this.cacheable = new CacheableLookup();
|
|
121
|
-
// 安装到http和https
|
|
122
|
-
this.cacheable.install(node_http_1.default.globalAgent);
|
|
123
|
-
this.cacheable.install(node_https_1.default.globalAgent);
|
|
124
|
-
}
|
|
125
72
|
// WBI签名
|
|
126
73
|
// 对 imgKey 和 subKey 进行字符顺序打乱编码
|
|
127
74
|
getMixinKey = (orig) => mixinKeyEncTab
|
package/lib/blive.d.ts
CHANGED
package/lib/blive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const koishi_1 = require("koishi");
|
|
4
|
-
const blive_message_listener_1 = require("blive-message-listener");
|
|
4
|
+
const blive_message_listener_1 = require("@akokko/blive-message-listener");
|
|
5
5
|
class BLive extends koishi_1.Service {
|
|
6
6
|
// 必要服务
|
|
7
7
|
static inject = ["ba"];
|
|
@@ -19,24 +19,29 @@ class BLive extends koishi_1.Service {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
async startLiveRoomListener(roomId, handler) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
try {
|
|
23
|
+
// 获取cookieStr
|
|
24
|
+
const cookiesStr = await this.ctx.ba.getCookiesForHeader();
|
|
25
|
+
// 获取自身信息
|
|
26
|
+
const mySelfInfo = await this.ctx.ba.getMyselfInfo();
|
|
27
|
+
// 创建实例并保存到Record中
|
|
28
|
+
this.listenerRecord[roomId] = (0, blive_message_listener_1.startListen)(Number.parseInt(roomId), handler, {
|
|
29
|
+
ws: {
|
|
30
|
+
headers: {
|
|
31
|
+
Cookie: cookiesStr,
|
|
32
|
+
},
|
|
33
|
+
uid: mySelfInfo.data.mid,
|
|
31
34
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
// logger
|
|
39
|
+
this.logger.info(`[${roomId}]监听直播间消息失败!错误:${e.message}`);
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
closeListener(roomId) {
|
|
37
43
|
// 判断直播间监听器是否关闭
|
|
38
|
-
if (!this.listenerRecord ||
|
|
39
|
-
!this.listenerRecord[roomId]?.closed) {
|
|
44
|
+
if (!this.listenerRecord || !this.listenerRecord[roomId]?.closed) {
|
|
40
45
|
// 输出logger
|
|
41
46
|
this.logger.info(`${roomId}直播间弹幕监听器无需关闭`);
|
|
42
47
|
}
|
package/lib/comRegister.js
CHANGED
|
@@ -997,6 +997,10 @@ class ComRegister {
|
|
|
997
997
|
let pushAtTimeTimer;
|
|
998
998
|
// 定义弹幕存放数组
|
|
999
999
|
const currentLiveDanmakuArr = [];
|
|
1000
|
+
// init flag
|
|
1001
|
+
let initFlag = false;
|
|
1002
|
+
// 连接中断flag
|
|
1003
|
+
let connFlag = false;
|
|
1000
1004
|
// 定义开播状态
|
|
1001
1005
|
let liveStatus = false;
|
|
1002
1006
|
// 定义channelIdArr总长度
|
|
@@ -1089,8 +1093,30 @@ class ComRegister {
|
|
|
1089
1093
|
};
|
|
1090
1094
|
// 构建消息处理函数
|
|
1091
1095
|
const handler = {
|
|
1092
|
-
|
|
1093
|
-
|
|
1096
|
+
onOpen: () => {
|
|
1097
|
+
if (!initFlag) {
|
|
1098
|
+
// init flag设置为true
|
|
1099
|
+
initFlag = true;
|
|
1100
|
+
// connFlag设置为false
|
|
1101
|
+
connFlag = false;
|
|
1102
|
+
// logger
|
|
1103
|
+
this.logger.info(`[${roomId}]直播间连接已建立!`);
|
|
1104
|
+
}
|
|
1105
|
+
},
|
|
1106
|
+
onClose: async () => {
|
|
1107
|
+
if (!connFlag) {
|
|
1108
|
+
// 更直播状态
|
|
1109
|
+
liveStatus = false;
|
|
1110
|
+
// 关闭定时推送
|
|
1111
|
+
pushAtTimeTimer?.();
|
|
1112
|
+
// 停止服务
|
|
1113
|
+
this.ctx.bl.closeListener(roomId);
|
|
1114
|
+
// 更改connFlag
|
|
1115
|
+
connFlag = true;
|
|
1116
|
+
// 发送消息
|
|
1117
|
+
await this.sendPrivateMsg(`[${roomId}]直播间连接已中断!`);
|
|
1118
|
+
this.logger.error(`[${roomId}]直播间连接已中断!`);
|
|
1119
|
+
}
|
|
1094
1120
|
},
|
|
1095
1121
|
onError: async () => {
|
|
1096
1122
|
// 更直播状态
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-bilibili-notify",
|
|
3
3
|
"description": "Koishi bilibili notify plugin",
|
|
4
|
-
"version": "3.2.1-alpha.
|
|
4
|
+
"version": "3.2.1-alpha.5",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Akokko <admin@akokko.com>"
|
|
7
7
|
],
|
|
@@ -27,24 +27,24 @@
|
|
|
27
27
|
"koishi": "^4.18.7"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"axios
|
|
32
|
-
"
|
|
30
|
+
"@akokko/blive-message-listener": "^0.5.1",
|
|
31
|
+
"axios": "^1.9.0",
|
|
32
|
+
"axios-cookiejar-support": "^6.0.2",
|
|
33
33
|
"cacheable-lookup": "^7.0.0",
|
|
34
34
|
"cron": "^4.3.0",
|
|
35
|
-
"jsdom": "^
|
|
36
|
-
"luxon": "^3.
|
|
35
|
+
"jsdom": "^26.1.0",
|
|
36
|
+
"luxon": "^3.6.1",
|
|
37
37
|
"md5": "^2.3.0",
|
|
38
38
|
"qrcode": "^1.5.4",
|
|
39
|
-
"tough-cookie": "^
|
|
39
|
+
"tough-cookie": "^5.1.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@biomejs/biome": "1.9.4",
|
|
43
|
-
"@types/luxon": "^3.
|
|
43
|
+
"@types/luxon": "^3.6.2",
|
|
44
44
|
"@types/md5": "^2.3.5",
|
|
45
45
|
"@types/qrcode": "^1.5.5",
|
|
46
46
|
"@types/tough-cookie": "^4.0.5",
|
|
47
|
-
"globals": "^
|
|
47
|
+
"globals": "^16.2.0",
|
|
48
48
|
"koishi-plugin-puppeteer": "^3.9.0"
|
|
49
49
|
},
|
|
50
50
|
"koishi": {
|
package/readme.md
CHANGED
|
@@ -260,6 +260,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
260
260
|
- ver 3.2.1-alpha.1 调整:将项目构建产物调整为 `esm`;
|
|
261
261
|
- ver 3.2.1-alpha.2 调整:将项目构建产物调整回 `cjs` 、将依赖 `cacheable-lookup` 导入方式更改为动态导入;
|
|
262
262
|
- ver 3.2.1-alpha.3 修复:直播检测 `WS` 初始化后自动断开连接;
|
|
263
|
+
- ver 3.2.1-alpha.4 优化:直播监听初始化没有提示;
|
|
264
|
+
- ver 3.2.1-alpha.5 修复:临时更换依赖 `blive-message-listener` 为 `@akokko/blive-message-listener` 以解决直播检测 `WS` 模式连接中断的问题;
|
|
263
265
|
|
|
264
266
|
## 交流群
|
|
265
267
|
|