koishi-plugin-bilibili-notify 1.2.5 → 1.2.6
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 +1 -0
- package/lib/biliAPI.js +17 -1
- package/package.json +1 -1
package/lib/biliAPI.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ declare class BiliAPI extends Service {
|
|
|
28
28
|
getLiveRoomInfo(roomId: string): Promise<any>;
|
|
29
29
|
getMasterInfo(mid: string): Promise<any>;
|
|
30
30
|
disposeNotifier(): void;
|
|
31
|
+
getRandomUserAgent(): string;
|
|
31
32
|
createNewClient(): void;
|
|
32
33
|
getTimeOfUTC8(): number;
|
|
33
34
|
getCookies(): string;
|
package/lib/biliAPI.js
CHANGED
|
@@ -150,13 +150,29 @@ class BiliAPI extends koishi_1.Service {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
disposeNotifier() { this.loginNotifier && this.loginNotifier.dispose(); }
|
|
153
|
+
getRandomUserAgent() {
|
|
154
|
+
const userAgents = [
|
|
155
|
+
// Chrome
|
|
156
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
|
|
157
|
+
// Firefox
|
|
158
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0',
|
|
159
|
+
// Safari
|
|
160
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15',
|
|
161
|
+
// Internet Explorer
|
|
162
|
+
'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; AS; rv:11.0) like Gecko',
|
|
163
|
+
// Edge
|
|
164
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.62',
|
|
165
|
+
];
|
|
166
|
+
const index = Math.floor(Math.random() * userAgents.length);
|
|
167
|
+
return userAgents[index];
|
|
168
|
+
}
|
|
153
169
|
createNewClient() {
|
|
154
170
|
this.jar = new tough_cookie_1.CookieJar();
|
|
155
171
|
this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
|
|
156
172
|
jar: this.jar,
|
|
157
173
|
headers: {
|
|
158
174
|
'Content-Type': 'application/json',
|
|
159
|
-
'User-Agent':
|
|
175
|
+
'User-Agent': this.getRandomUserAgent(),
|
|
160
176
|
'Origin': 'https://www.bilibili.com',
|
|
161
177
|
'Referer': 'https://www.bilibili.com/'
|
|
162
178
|
}
|