koishi-plugin-bilibili-notify 1.0.7-alpha.0 → 1.0.8
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/comRegister.d.ts +1 -0
- package/lib/comRegister.js +82 -62
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/comRegister.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare class ComRegister {
|
|
|
23
23
|
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<void>;
|
|
24
24
|
subShow(): string;
|
|
25
25
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
|
26
|
+
updateSubNotifier(ctx: Context): void;
|
|
26
27
|
getSubFromDatabase(ctx: Context): Promise<string[]>;
|
|
27
28
|
unsubSingle(ctx: Context, id: string, type: number): string;
|
|
28
29
|
checkIfIsLogin(ctx: Context): Promise<boolean>;
|
package/lib/comRegister.js
CHANGED
|
@@ -199,6 +199,9 @@ class ComRegister {
|
|
|
199
199
|
// 若用户UID为空则直接返回
|
|
200
200
|
if (!uid)
|
|
201
201
|
return '用户UID不能为空';
|
|
202
|
+
// -d -l两个选项不能同时存在
|
|
203
|
+
if (options.dynamic && options.live)
|
|
204
|
+
return '需要取消订阅该UP主请直接使用指令bili unsub 用户UID';
|
|
202
205
|
// 定义是否存在
|
|
203
206
|
let exist;
|
|
204
207
|
await Promise.all(this.subManager.map(async (sub, i) => {
|
|
@@ -221,11 +224,13 @@ class ComRegister {
|
|
|
221
224
|
// 从数据库中删除订阅
|
|
222
225
|
await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
|
|
223
226
|
// 将该订阅对象从订阅管理对象中移除
|
|
224
|
-
this.subManager
|
|
227
|
+
this.subManager.splice(i, 1);
|
|
225
228
|
// id--
|
|
226
229
|
this.num--;
|
|
227
230
|
// 发送成功通知
|
|
228
231
|
session.send('已取消订阅该用户');
|
|
232
|
+
// 更新控制台提示
|
|
233
|
+
this.updateSubNotifier(ctx);
|
|
229
234
|
// 将存在flag设置为true
|
|
230
235
|
exist = true;
|
|
231
236
|
}
|
|
@@ -509,7 +514,7 @@ class ComRegister {
|
|
|
509
514
|
let firstSubscription = true;
|
|
510
515
|
let timePoint;
|
|
511
516
|
// Test code
|
|
512
|
-
let timer = 0
|
|
517
|
+
// let timer = 0
|
|
513
518
|
return async () => {
|
|
514
519
|
// Test code
|
|
515
520
|
/* this.logger.info('timer:' + timer++)
|
|
@@ -797,6 +802,17 @@ class ComRegister {
|
|
|
797
802
|
}
|
|
798
803
|
}
|
|
799
804
|
}
|
|
805
|
+
updateSubNotifier(ctx) {
|
|
806
|
+
// 更新控制台提示
|
|
807
|
+
this.subNotifier && this.subNotifier.dispose();
|
|
808
|
+
// 获取subTable
|
|
809
|
+
const subTable = this.subShow();
|
|
810
|
+
// 设置更新后的提示
|
|
811
|
+
this.subNotifier = ctx.notifier.create({
|
|
812
|
+
type: 'primary',
|
|
813
|
+
content: subTable
|
|
814
|
+
});
|
|
815
|
+
}
|
|
800
816
|
async getSubFromDatabase(ctx) {
|
|
801
817
|
// 如果未登录,则直接返回
|
|
802
818
|
if (!(await this.checkIfIsLogin(ctx)))
|
|
@@ -821,6 +837,13 @@ class ComRegister {
|
|
|
821
837
|
let bot;
|
|
822
838
|
// 循环遍历
|
|
823
839
|
for (const sub of subData) {
|
|
840
|
+
// 判断是否存在没有任何订阅的数据
|
|
841
|
+
if (!sub.dynamic && !sub.live) { // 存在未订阅任何项目的数据
|
|
842
|
+
// 删除该条数据
|
|
843
|
+
ctx.database.remove('bilibili', { id: sub.id });
|
|
844
|
+
// 跳过下面的步骤
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
824
847
|
// 拿到对应bot
|
|
825
848
|
switch (sub.platform) {
|
|
826
849
|
case 'qq': bot = this.qqBot;
|
|
@@ -899,73 +922,70 @@ class ComRegister {
|
|
|
899
922
|
this.subManager.push(subManagerItem);
|
|
900
923
|
}
|
|
901
924
|
// 在控制台中显示订阅对象
|
|
902
|
-
|
|
903
|
-
// 如果已经存在Notifier则清除原先的Notifier
|
|
904
|
-
this.subNotifier && this.subNotifier.dispose();
|
|
905
|
-
// 创建Notifier
|
|
906
|
-
this.subNotifier = ctx.notifier.create({
|
|
907
|
-
type: 'primary',
|
|
908
|
-
content: subTable
|
|
909
|
-
});
|
|
925
|
+
this.updateSubNotifier(ctx);
|
|
910
926
|
}
|
|
911
927
|
unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
|
|
912
928
|
let index;
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
929
|
+
const checkIfNoSubExist = (index) => {
|
|
930
|
+
if (!this.subManager[index].dynamic && !this.subManager[index].live) {
|
|
931
|
+
// 获取要删除行的id
|
|
932
|
+
const id = this.subManager[index].id;
|
|
933
|
+
// 从管理对象中移除
|
|
934
|
+
this.subManager.splice(index, 1);
|
|
935
|
+
// 从数据库中删除
|
|
936
|
+
ctx.database.remove('bilibili', [id]);
|
|
937
|
+
// num--
|
|
938
|
+
this.num--;
|
|
939
|
+
return '已取消订阅该用户';
|
|
940
|
+
}
|
|
941
|
+
return null;
|
|
942
|
+
};
|
|
943
|
+
try {
|
|
944
|
+
switch (type) {
|
|
945
|
+
case 0: { // 取消Live订阅
|
|
946
|
+
index = this.subManager.findIndex(sub => sub.roomId === id);
|
|
947
|
+
if (index === -1)
|
|
948
|
+
return '未订阅该用户,无需取消订阅';
|
|
949
|
+
// 取消订阅
|
|
950
|
+
this.subManager[index].live && this.subManager[index].liveDispose();
|
|
951
|
+
this.subManager[index].liveDispose = null;
|
|
952
|
+
this.subManager[index].live = false;
|
|
953
|
+
// 如果没有对这个UP的任何订阅,则移除
|
|
954
|
+
const info = checkIfNoSubExist(index);
|
|
955
|
+
if (info)
|
|
956
|
+
return info;
|
|
957
|
+
// 更新数据库
|
|
958
|
+
ctx.database.upsert('bilibili', [{
|
|
959
|
+
id: +`${this.subManager[index].id}`,
|
|
960
|
+
live: 0
|
|
961
|
+
}]);
|
|
962
|
+
return '已取消订阅Live';
|
|
931
963
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
const id = this.subManager[index].id;
|
|
951
|
-
// 从管理对象中移除
|
|
952
|
-
this.subManager = this.subManager.splice(index, index);
|
|
953
|
-
// 从数据库中删除
|
|
954
|
-
ctx.database.remove('bilibili', [id]);
|
|
955
|
-
// num--
|
|
956
|
-
this.num--;
|
|
957
|
-
return '已取消订阅该用户';
|
|
964
|
+
case 1: { // 取消Dynamic订阅
|
|
965
|
+
index = this.subManager.findIndex(sub => sub.uid === id);
|
|
966
|
+
if (index === -1)
|
|
967
|
+
return '未订阅该用户,无需取消订阅';
|
|
968
|
+
// 取消订阅
|
|
969
|
+
this.subManager[index].dynamic && this.subManager[index].dynamicDispose();
|
|
970
|
+
this.subManager[index].dynamicDispose = null;
|
|
971
|
+
this.subManager[index].dynamic = false;
|
|
972
|
+
// 如果没有对这个UP的任何订阅,则移除
|
|
973
|
+
const info = checkIfNoSubExist(index);
|
|
974
|
+
if (info)
|
|
975
|
+
return info;
|
|
976
|
+
// 更新数据库
|
|
977
|
+
ctx.database.upsert('bilibili', [{
|
|
978
|
+
id: +`${this.subManager[index].id}`,
|
|
979
|
+
dynamic: 0
|
|
980
|
+
}]);
|
|
981
|
+
return '已取消订阅Dynamic';
|
|
958
982
|
}
|
|
959
|
-
this.subManager[index].dynamicDispose = null;
|
|
960
|
-
this.subManager[index].dynamic = false;
|
|
961
|
-
// 更新数据库
|
|
962
|
-
ctx.database.upsert('bilibili', [{
|
|
963
|
-
id: +`${this.subManager[index].id}`,
|
|
964
|
-
dynamic: 0
|
|
965
|
-
}]);
|
|
966
|
-
return '已取消订阅Dynamic';
|
|
967
983
|
}
|
|
968
984
|
}
|
|
985
|
+
finally {
|
|
986
|
+
// 执行完该方法后,保证执行一次updateSubNotifier()
|
|
987
|
+
this.updateSubNotifier(ctx);
|
|
988
|
+
}
|
|
969
989
|
}
|
|
970
990
|
async checkIfIsLogin(ctx) {
|
|
971
991
|
if ((await ctx.database.get('loginBili', 1)).length !== 0) { // 数据库中有数据
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
- ver 1.0.5 修复了用户非法篡改数据库内容可能导致程序异常运行的bug,修复了UP主开播动态推送空白卡片的bug
|
|
84
84
|
- ver 1.0.6 修复了转发动态转发信息出现undefined的bug,修复了再次登录订阅显示错误的bug,优化了动态推送的逻辑
|
|
85
85
|
- ver 1.0.7 修复了在已登录情况下,再次登录会导致重复订阅和提示用户未订阅任何UP主的提示(实际上已订阅)的bug,新增了订阅对象在控制台的显示,优化了bili show指令的逻辑
|
|
86
|
+
- ver 1.0.8 修复了取消订阅的bug
|
|
86
87
|
|
|
87
88
|
## 感谢
|
|
88
89
|
|