koishi-plugin-bilibili-notify 1.2.10 → 1.2.11-alpha.0
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 +9 -2
- package/lib/biliAPI.js +10 -3
- package/lib/comRegister.d.ts +1 -0
- package/lib/comRegister.js +22 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -1
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, Service } from "koishi";
|
|
1
|
+
import { Context, Schema, Service } from "koishi";
|
|
2
2
|
import { CookieJar } from 'tough-cookie';
|
|
3
3
|
import { Notifier } from "@koishijs/plugin-notifier";
|
|
4
4
|
declare module 'koishi' {
|
|
@@ -10,11 +10,12 @@ declare class BiliAPI extends Service {
|
|
|
10
10
|
static inject: string[];
|
|
11
11
|
jar: CookieJar;
|
|
12
12
|
client: any;
|
|
13
|
+
apiConfig: BiliAPI.Config;
|
|
13
14
|
loginData: any;
|
|
14
15
|
loginNotifier: Notifier;
|
|
15
16
|
refreshCookieTimer: Function;
|
|
16
17
|
loginInfoIsLoaded: boolean;
|
|
17
|
-
constructor(ctx: Context);
|
|
18
|
+
constructor(ctx: Context, config: BiliAPI.Config);
|
|
18
19
|
protected start(): void | Promise<void>;
|
|
19
20
|
protected stop(): void | Promise<void>;
|
|
20
21
|
getServerUTCTime(): Promise<number>;
|
|
@@ -41,4 +42,10 @@ declare class BiliAPI extends Service {
|
|
|
41
42
|
enableRefreshCookiesDetect(): void;
|
|
42
43
|
checkIfTokenNeedRefresh(refreshToken: string, csrf: string, times?: number): Promise<void>;
|
|
43
44
|
}
|
|
45
|
+
declare namespace BiliAPI {
|
|
46
|
+
interface Config {
|
|
47
|
+
userAgent: string;
|
|
48
|
+
}
|
|
49
|
+
const Config: Schema<Config>;
|
|
50
|
+
}
|
|
44
51
|
export default BiliAPI;
|
package/lib/biliAPI.js
CHANGED
|
@@ -26,19 +26,20 @@ class BiliAPI extends koishi_1.Service {
|
|
|
26
26
|
static inject = ['database', 'wbi', 'notifier'];
|
|
27
27
|
jar;
|
|
28
28
|
client;
|
|
29
|
+
apiConfig;
|
|
29
30
|
loginData;
|
|
30
31
|
loginNotifier;
|
|
31
32
|
refreshCookieTimer;
|
|
32
33
|
loginInfoIsLoaded = false;
|
|
33
|
-
constructor(ctx) {
|
|
34
|
+
constructor(ctx, config) {
|
|
34
35
|
super(ctx, 'biliAPI');
|
|
36
|
+
this.apiConfig = config;
|
|
35
37
|
}
|
|
36
38
|
start() {
|
|
37
39
|
// 创建新的http客户端(axios)
|
|
38
40
|
this.createNewClient();
|
|
39
41
|
// 从数据库加载cookies
|
|
40
42
|
this.loadCookiesFromDatabase();
|
|
41
|
-
// logger
|
|
42
43
|
// this.logger.info('工作中')
|
|
43
44
|
}
|
|
44
45
|
stop() {
|
|
@@ -167,7 +168,8 @@ class BiliAPI extends koishi_1.Service {
|
|
|
167
168
|
jar: this.jar,
|
|
168
169
|
headers: {
|
|
169
170
|
'Content-Type': 'application/json',
|
|
170
|
-
'User-Agent': this.
|
|
171
|
+
'User-Agent': this.apiConfig.userAgent !== 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' ?
|
|
172
|
+
this.apiConfig.userAgent : this.getRandomUserAgent(),
|
|
171
173
|
'Origin': 'https://www.bilibili.com',
|
|
172
174
|
'Referer': 'https://www.bilibili.com/'
|
|
173
175
|
}
|
|
@@ -389,4 +391,9 @@ class BiliAPI extends koishi_1.Service {
|
|
|
389
391
|
// 没有问题,cookies已更新完成
|
|
390
392
|
}
|
|
391
393
|
}
|
|
394
|
+
(function (BiliAPI) {
|
|
395
|
+
BiliAPI.Config = koishi_1.Schema.object({
|
|
396
|
+
userAgent: koishi_1.Schema.string()
|
|
397
|
+
});
|
|
398
|
+
})(BiliAPI || (BiliAPI = {}));
|
|
392
399
|
exports.default = BiliAPI;
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare class ComRegister {
|
|
|
38
38
|
checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
|
|
39
39
|
getSubFromDatabase(ctx: Context): Promise<void>;
|
|
40
40
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
41
|
+
unsubAll(ctx: Context, bot: Bot<Context>, uid: string): void;
|
|
41
42
|
checkIfIsLogin(ctx: Context): Promise<boolean>;
|
|
42
43
|
}
|
|
43
44
|
declare namespace ComRegister {
|
package/lib/comRegister.js
CHANGED
|
@@ -794,9 +794,10 @@ class ComRegister {
|
|
|
794
794
|
default: await this.sendPrivateMsg(bot, '获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
|
|
795
795
|
}
|
|
796
796
|
// 取消订阅
|
|
797
|
-
this.
|
|
797
|
+
this.unsubAll(ctx, bot, uid);
|
|
798
|
+
// this.unsubSingle(ctx, uid, 1) /* 1为取消动态订阅 */
|
|
798
799
|
// 发送取消订阅消息
|
|
799
|
-
await this.sendPrivateMsg(bot, `UID:${uid},已取消订阅动态`)
|
|
800
|
+
// await this.sendPrivateMsg(bot, `UID:${uid},已取消订阅动态`)
|
|
800
801
|
// 结束循环
|
|
801
802
|
return;
|
|
802
803
|
}
|
|
@@ -1368,6 +1369,25 @@ class ComRegister {
|
|
|
1368
1369
|
this.updateSubNotifier(ctx);
|
|
1369
1370
|
}
|
|
1370
1371
|
}
|
|
1372
|
+
unsubAll(ctx, bot, uid) {
|
|
1373
|
+
this.subManager.filter(sub => sub.uid === uid).map(async (sub, i) => {
|
|
1374
|
+
// 取消全部订阅 执行dispose方法,销毁定时器
|
|
1375
|
+
if (sub.dynamic)
|
|
1376
|
+
this.subManager[i].dynamicDispose();
|
|
1377
|
+
if (sub.live)
|
|
1378
|
+
this.subManager[i].liveDispose();
|
|
1379
|
+
// 从数据库中删除订阅
|
|
1380
|
+
await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
|
|
1381
|
+
// 将该订阅对象从订阅管理对象中移除
|
|
1382
|
+
this.subManager.splice(i, 1);
|
|
1383
|
+
// id--
|
|
1384
|
+
this.num--;
|
|
1385
|
+
// 发送成功通知
|
|
1386
|
+
this.sendPrivateMsg(bot, `UID:${uid},已取消订阅该用户`);
|
|
1387
|
+
// 更新控制台提示
|
|
1388
|
+
this.updateSubNotifier(ctx);
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1371
1391
|
async checkIfIsLogin(ctx) {
|
|
1372
1392
|
if ((await ctx.database.get('loginBili', 1)).length !== 0) { // 数据库中有数据
|
|
1373
1393
|
// 检查cookie中是否有值
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -76,6 +76,9 @@ exports.Config = koishi_1.Schema.object({
|
|
|
76
76
|
.role('')
|
|
77
77
|
.default('render')
|
|
78
78
|
.description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
|
|
79
|
+
userAgent: koishi_1.Schema.string()
|
|
80
|
+
.default('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36')
|
|
81
|
+
.description('设置请求头User-Agen,请求出现-352时可以尝试修改'),
|
|
79
82
|
dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
|
|
80
83
|
dynamicUrl: koishi_1.Schema.boolean()
|
|
81
84
|
.default(false)
|
|
@@ -172,7 +175,9 @@ class ServerManager extends koishi_1.Service {
|
|
|
172
175
|
this.registerPlugin();
|
|
173
176
|
}
|
|
174
177
|
registerPlugin = () => {
|
|
175
|
-
const biliApi = this.ctx.plugin(biliAPI_1.default
|
|
178
|
+
const biliApi = this.ctx.plugin(biliAPI_1.default, {
|
|
179
|
+
userAgent: globalConfig.userAgent
|
|
180
|
+
});
|
|
176
181
|
const generateImg = this.ctx.plugin(generateImg_1.default, {
|
|
177
182
|
renderType: this.renderType,
|
|
178
183
|
filter: globalConfig.filter,
|
package/package.json
CHANGED