koishi-plugin-bilibili-notify 1.0.6-alpha.0 → 1.0.7-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.
@@ -1,9 +1,11 @@
1
1
  import { Bot, Context, Logger, Schema, Session } from "koishi";
2
+ import { Notifier } from "@koishijs/plugin-notifier";
2
3
  declare class ComRegister {
3
4
  static inject: string[];
4
5
  logger: Logger;
5
6
  config: ComRegister.Config;
6
7
  num: number;
8
+ subNotifier: Notifier;
7
9
  subManager: {
8
10
  id: number;
9
11
  uid: string;
@@ -19,8 +21,9 @@ declare class ComRegister {
19
21
  constructor(ctx: Context, config: ComRegister.Config);
20
22
  dynamicDetect(ctx: Context, bot: Bot<Context>, guildId: string, uid: string): () => Promise<void | string[]>;
21
23
  liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<void>;
24
+ subShow(): string;
22
25
  checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
23
- getSubFromDatabase(ctx: Context): Promise<void>;
26
+ getSubFromDatabase(ctx: Context): Promise<string[]>;
24
27
  unsubSingle(ctx: Context, id: string, type: number): string;
25
28
  checkIfIsLogin(ctx: Context): Promise<boolean>;
26
29
  }
@@ -17,6 +17,7 @@ class ComRegister {
17
17
  logger;
18
18
  config;
19
19
  num = 0;
20
+ subNotifier;
20
21
  subManager = [];
21
22
  // QQ群机器人
22
23
  qqBot;
@@ -175,13 +176,13 @@ class ComRegister {
175
176
  }]);
176
177
  // 销毁定时器
177
178
  dispose();
179
+ // 订阅之前的订阅
180
+ await this.getSubFromDatabase(ctx);
178
181
  // 清除控制台通知
179
182
  ctx.biliAPI.disposeNotifier();
180
183
  // 发送成功登录推送
181
184
  await session.send('登录成功!');
182
- // 订阅之前的订阅
183
- await this.getSubFromDatabase(ctx);
184
- // 调用bili show指令
185
+ // bili show
185
186
  await session.execute('bili show');
186
187
  return;
187
188
  }
@@ -236,13 +237,9 @@ class ComRegister {
236
237
  .subcommand('.show', '展示订阅对象')
237
238
  .usage('展示订阅对象')
238
239
  .example('bili show')
239
- .action(async ({ session }) => {
240
- let table = ``;
241
- this.subManager.forEach(sub => {
242
- table += `UID:${sub.uid} ${sub.dynamic ? '已订阅动态' : ''} ${sub.live ? '已订阅直播' : ''}` + '\n';
243
- });
244
- !table && session.send('没有订阅任何UP');
245
- table && session.send(table);
240
+ .action(() => {
241
+ const subTable = this.subShow();
242
+ return subTable;
246
243
  });
247
244
  ctx.command('bili')
248
245
  .subcommand('.sub <mid:string> [guildId:string]', '订阅用户动态和直播通知')
@@ -382,6 +379,15 @@ class ComRegister {
382
379
  // 发送订阅消息通知
383
380
  await bot.sendMessage(sub.targetId, `订阅${userData.info.uname}动态通知`);
384
381
  }
382
+ // 新增订阅展示到控制台
383
+ // 获取subTable
384
+ const subTable = this.subShow();
385
+ // 判断之前是否存在Notifier
386
+ this.subNotifier && this.subNotifier.dispose();
387
+ this.subNotifier = ctx.notifier.create({
388
+ type: 'primary',
389
+ content: subTable
390
+ });
385
391
  });
386
392
  ctx.command('bili')
387
393
  .subcommand('.dynamic <uid:string> <guildId:string>', '订阅用户动态推送', { hidden: true })
@@ -748,6 +754,14 @@ class ComRegister {
748
754
  }
749
755
  };
750
756
  }
757
+ subShow() {
758
+ // 在控制台中显示订阅对象
759
+ let table = ``;
760
+ this.subManager.forEach(sub => {
761
+ table += `UID:${sub.uid} ${sub.dynamic ? '已订阅动态' : ''} ${sub.live ? '已订阅直播' : ''}` + '\n';
762
+ });
763
+ return table ? table : '没有订阅任何UP';
764
+ }
751
765
  async checkIfNeedSub(comNeed, subType, session, data) {
752
766
  if (comNeed) {
753
767
  if (subType === '直播' && !data.live_room) {
@@ -784,15 +798,18 @@ class ComRegister {
784
798
  }
785
799
  }
786
800
  async getSubFromDatabase(ctx) {
787
- if (!(await this.checkIfIsLogin(ctx))) { // 如果未登录,则直接返回
801
+ // 如果未登录,则直接返回
802
+ if (!(await this.checkIfIsLogin(ctx)))
803
+ return;
804
+ // 已存在订阅管理对象,不再进行订阅操作
805
+ if (this.subManager.length !== 0)
788
806
  return;
789
- }
790
807
  // 从数据库中获取数据
791
808
  const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
792
809
  // 设定订阅数量
793
810
  this.num = subData.length;
794
811
  // 如果订阅数量超过三个则被非法修改数据库
795
- // 向管理员发送重新订阅通知
812
+ // 在控制台提示重新订阅
796
813
  if (this.num > 3) {
797
814
  ctx.notifier.create({
798
815
  type: 'danger',
@@ -803,7 +820,7 @@ class ComRegister {
803
820
  // 定义Bot
804
821
  let bot;
805
822
  // 循环遍历
806
- subData.forEach(async (sub) => {
823
+ for (const sub of subData) {
807
824
  // 拿到对应bot
808
825
  switch (sub.platform) {
809
826
  case 'qq': bot = this.qqBot;
@@ -880,7 +897,15 @@ class ComRegister {
880
897
  }
881
898
  // 保存新订阅对象
882
899
  this.subManager.push(subManagerItem);
883
- // 发送订阅成功通知
900
+ }
901
+ // 在控制台中显示订阅对象
902
+ const subTable = this.subShow();
903
+ // 如果已经存在Notifier则清除原先的Notifier
904
+ this.subNotifier && this.subNotifier.dispose();
905
+ // 创建Notifier
906
+ this.subNotifier = ctx.notifier.create({
907
+ type: 'primary',
908
+ content: subTable
884
909
  });
885
910
  }
886
911
  unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
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": "1.0.6-alpha.0",
4
+ "version": "1.0.7-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -81,7 +81,8 @@
81
81
  - ver 1.0.3 修复了一些bug,提供用户自己选择推送卡片字体样式的选项
82
82
  - ver 1.0.4 修复了重复推送的bug,提供用户选择推送卡片渲染方式的选项
83
83
  - ver 1.0.5 修复了用户非法篡改数据库内容可能导致程序异常运行的bug,修复了UP主开播动态推送空白卡片的bug
84
- - ver 1.0.6 修复了转发动态转发信息出现undefined的bug,优化了动态推送的逻辑
84
+ - ver 1.0.6 修复了转发动态转发信息出现undefined的bug,修复了再次登录订阅显示错误的bug,优化了动态推送的逻辑
85
+ - ver 1.0.7 修复了在已登录情况下,再次登录会导致重复订阅和提示用户未订阅任何UP主的提示(实际上已订阅)的bug,新增了订阅对象在控制台的显示,优化了bili show指令的逻辑
85
86
 
86
87
  ## 感谢
87
88