koishi-plugin-noah 1.1.1 → 1.1.3
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/constants.d.ts +6 -6
- package/lib/core/services/card-service.d.ts +32 -17
- package/lib/core/services/server-service.d.ts +36 -14
- package/lib/core/services/user-service.d.ts +13 -9
- package/lib/core/utils/card.d.ts +10 -8
- package/lib/core/utils/role.d.ts +16 -0
- package/lib/drawer/BaseDrawer.d.ts +5 -5
- package/lib/drawer/DrawerFactory.d.ts +6 -0
- package/lib/drawer/core/index.d.ts +7 -4
- package/lib/drawer/iidx/index.d.ts +14 -5
- package/lib/drawer/index.d.ts +16 -1
- package/lib/drawer/sdvx/index.d.ts +17 -9
- package/lib/games/sdvx/config.d.ts +5 -0
- package/lib/games/sdvx/services/music-service.d.ts +11 -0
- package/lib/games/sdvx/services/score-service.d.ts +10 -6
- package/lib/games/sdvx/types/index.d.ts +18 -0
- package/lib/games/sdvx/utils/vf.d.ts +9 -9
- package/lib/index.js +234 -89
- package/lib/servers/Asphyxia/index.d.ts +3 -0
- package/lib/servers/Mao/index.d.ts +3 -0
- package/lib/servers/ServerFactory.d.ts +6 -0
- package/lib/servers/index.d.ts +15 -0
- package/lib/servers/utils/difficulty.d.ts +8 -8
- package/lib/servers/utils/grade.d.ts +10 -0
- package/lib/servers/utils/xml.d.ts +7 -8
- package/lib/types/config.d.ts +40 -0
- package/lib/types/index.d.ts +48 -32
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -333,6 +333,7 @@ var CardService = class {
|
|
|
333
333
|
tableName = "card";
|
|
334
334
|
/**
|
|
335
335
|
* 获取所有卡片列表
|
|
336
|
+
* @returns 包含所有卡片的数组
|
|
336
337
|
*/
|
|
337
338
|
async getAllCards() {
|
|
338
339
|
const cards = await this.ctx.database.get(this.tableName, {});
|
|
@@ -342,9 +343,9 @@ var CardService = class {
|
|
|
342
343
|
}));
|
|
343
344
|
}
|
|
344
345
|
/**
|
|
345
|
-
*
|
|
346
|
-
* @param uid
|
|
347
|
-
* @returns
|
|
346
|
+
* 根据用户ID获取卡片列表
|
|
347
|
+
* @param uid - 用户ID
|
|
348
|
+
* @returns 该用户绑定的卡片完整信息列表
|
|
348
349
|
*/
|
|
349
350
|
async getCardsByUid(uid) {
|
|
350
351
|
const rows = await this.ctx.database.get("user_card", { uid }, ["cid"]);
|
|
@@ -355,7 +356,9 @@ var CardService = class {
|
|
|
355
356
|
}));
|
|
356
357
|
}
|
|
357
358
|
/**
|
|
358
|
-
*
|
|
359
|
+
* 根据卡片ID获取卡片信息
|
|
360
|
+
* @param id - 卡片ID
|
|
361
|
+
* @returns 卡片信息,不存在则返回null
|
|
359
362
|
*/
|
|
360
363
|
async getCardById(id) {
|
|
361
364
|
const rows = await this.ctx.database.get(this.tableName, id);
|
|
@@ -366,7 +369,9 @@ var CardService = class {
|
|
|
366
369
|
};
|
|
367
370
|
}
|
|
368
371
|
/**
|
|
369
|
-
*
|
|
372
|
+
* 根据卡号获取卡片信息
|
|
373
|
+
* @param code - 卡号
|
|
374
|
+
* @returns 卡片信息,不存在则返回null
|
|
370
375
|
*/
|
|
371
376
|
async getCardByCode(code) {
|
|
372
377
|
const rows = await this.ctx.database.get(this.tableName, { code });
|
|
@@ -377,7 +382,9 @@ var CardService = class {
|
|
|
377
382
|
};
|
|
378
383
|
}
|
|
379
384
|
/**
|
|
380
|
-
*
|
|
385
|
+
* 根据卡片名称获取卡片信息
|
|
386
|
+
* @param name - 卡片名称
|
|
387
|
+
* @returns 卡片信息,不存在则返回null
|
|
381
388
|
*/
|
|
382
389
|
async getCardByName(name13) {
|
|
383
390
|
const rows = await this.ctx.database.get(this.tableName, { name: name13 });
|
|
@@ -388,12 +395,12 @@ var CardService = class {
|
|
|
388
395
|
};
|
|
389
396
|
}
|
|
390
397
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param uid
|
|
393
|
-
* @param code
|
|
394
|
-
* @param name
|
|
395
|
-
* @param defaultServerId 默认服务器
|
|
396
|
-
* @returns 创建成功后包含自动填充
|
|
398
|
+
* 创建一张新卡片
|
|
399
|
+
* @param uid - 用户ID
|
|
400
|
+
* @param code - 卡片卡号
|
|
401
|
+
* @param name - 卡片名称
|
|
402
|
+
* @param defaultServerId - 默认服务器ID(若没有默认服务器则为0)
|
|
403
|
+
* @returns 创建成功后包含自动填充ID等字段的完整对象
|
|
397
404
|
*/
|
|
398
405
|
async createCard(uid, code, name13, defaultServerId = 0) {
|
|
399
406
|
const data = {
|
|
@@ -409,10 +416,11 @@ var CardService = class {
|
|
|
409
416
|
};
|
|
410
417
|
}
|
|
411
418
|
/**
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* @param id
|
|
415
|
-
* @param partial
|
|
419
|
+
* 更新卡片信息
|
|
420
|
+
* 可更新 code、name、defaultServerId
|
|
421
|
+
* @param id - 卡片ID
|
|
422
|
+
* @param partial - 要更新的字段
|
|
423
|
+
* @returns 无返回值的Promise
|
|
416
424
|
*/
|
|
417
425
|
async updateCard(id, partial) {
|
|
418
426
|
if (partial.defaultServerId === void 0) {
|
|
@@ -422,7 +430,8 @@ var CardService = class {
|
|
|
422
430
|
}
|
|
423
431
|
/**
|
|
424
432
|
* 删除卡片
|
|
425
|
-
* @param id 卡片
|
|
433
|
+
* @param id - 卡片ID
|
|
434
|
+
* @returns 无返回值的Promise
|
|
426
435
|
*/
|
|
427
436
|
async removeCard(id) {
|
|
428
437
|
await this.ctx.database.remove(this.tableName, id);
|
|
@@ -437,6 +446,16 @@ var CardService = class {
|
|
|
437
446
|
}
|
|
438
447
|
}
|
|
439
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* 根据用户ID获取默认卡片
|
|
451
|
+
* @param uid - 用户ID
|
|
452
|
+
* @returns 用户设置的默认卡片,若不存在则返回null
|
|
453
|
+
*/
|
|
454
|
+
async getDefaultCardByUid(uid) {
|
|
455
|
+
const userRes = await this.ctx.database.get("user", { id: uid }, ["defaultCardId"]);
|
|
456
|
+
if (!userRes[0] || userRes[0].defaultCardId === void 0 || userRes[0].defaultCardId === 0) return null;
|
|
457
|
+
return await this.getCardById(userRes[0].defaultCardId);
|
|
458
|
+
}
|
|
440
459
|
};
|
|
441
460
|
|
|
442
461
|
// src/core/services/user-service.ts
|
|
@@ -448,25 +467,29 @@ var UserService = class {
|
|
|
448
467
|
__name(this, "UserService");
|
|
449
468
|
}
|
|
450
469
|
/**
|
|
451
|
-
*
|
|
452
|
-
* @param uid
|
|
453
|
-
* @param serverId
|
|
470
|
+
* 更新用户的默认服务器ID
|
|
471
|
+
* @param uid - 用户ID
|
|
472
|
+
* @param serverId - 服务器ID
|
|
473
|
+
* @returns 无返回值的Promise
|
|
454
474
|
*/
|
|
455
475
|
async updateUserDefaultServer(uid, serverId) {
|
|
456
476
|
await this.ctx.database.set("user", uid, { defaultServerId: serverId });
|
|
457
477
|
}
|
|
458
478
|
/**
|
|
459
|
-
*
|
|
460
|
-
* @param uid
|
|
461
|
-
* @param cardId
|
|
479
|
+
* 更新用户的默认卡片ID
|
|
480
|
+
* @param uid - 用户ID
|
|
481
|
+
* @param cardId - 卡片ID
|
|
482
|
+
* @returns 无返回值的Promise
|
|
462
483
|
*/
|
|
463
484
|
async updateUserDefaultCard(uid, cardId) {
|
|
464
485
|
await this.ctx.database.set("user", uid, { defaultCardId: cardId });
|
|
465
486
|
}
|
|
466
487
|
/**
|
|
467
|
-
*
|
|
468
|
-
* @param
|
|
469
|
-
* @param
|
|
488
|
+
* 更新频道的默认服务器ID
|
|
489
|
+
* @param platform - 平台标识
|
|
490
|
+
* @param cid - 频道ID
|
|
491
|
+
* @param serverId - 服务器ID
|
|
492
|
+
* @returns 无返回值的Promise
|
|
470
493
|
*/
|
|
471
494
|
async updateChannelDefaultServer(platform, cid, serverId) {
|
|
472
495
|
await this.ctx.database.setChannel(platform, cid, { defaultServerId: serverId });
|
|
@@ -496,7 +519,8 @@ function bind(ctx, config) {
|
|
|
496
519
|
if (!cardName) return session.text("commands.timeout");
|
|
497
520
|
if (cardName.includes(" ")) return session.text(".invalid-name");
|
|
498
521
|
const res = await cardService.createCard(session.user.id, cardCode, cardName);
|
|
499
|
-
|
|
522
|
+
const defaultCard = await cardService.getDefaultCardByUid(session.user.id);
|
|
523
|
+
if (!defaultCard) {
|
|
500
524
|
await userService.updateUserDefaultCard(session.user.id, res.id);
|
|
501
525
|
}
|
|
502
526
|
return session.text(".success", { cardName, cardCode });
|
|
@@ -518,30 +542,33 @@ var ServerService = class {
|
|
|
518
542
|
tableName = "server";
|
|
519
543
|
/**
|
|
520
544
|
* 获取所有服务器列表
|
|
545
|
+
* @returns 服务器列表
|
|
521
546
|
*/
|
|
522
547
|
async getAllServers() {
|
|
523
548
|
return await this.ctx.database.get(this.tableName, {});
|
|
524
549
|
}
|
|
525
550
|
/**
|
|
526
|
-
*
|
|
527
|
-
* @param uid
|
|
528
|
-
* @returns
|
|
551
|
+
* 根据用户ID获取服务器列表
|
|
552
|
+
* @param uid - 用户ID
|
|
553
|
+
* @returns 该用户绑定的服务器完整信息列表
|
|
529
554
|
*/
|
|
530
555
|
async getServersByUid(uid) {
|
|
531
556
|
const rows = await this.ctx.database.get("user_server", { uid }, ["sid"]);
|
|
532
557
|
return await this.ctx.database.get("server", rows.map((obj) => obj.sid));
|
|
533
558
|
}
|
|
534
559
|
/**
|
|
535
|
-
*
|
|
536
|
-
* @param cid
|
|
537
|
-
* @returns
|
|
560
|
+
* 根据频道ID获取服务器列表
|
|
561
|
+
* @param cid - 频道ID
|
|
562
|
+
* @returns 该频道绑定的服务器完整信息列表
|
|
538
563
|
*/
|
|
539
564
|
async getServersByCid(cid) {
|
|
540
565
|
const rows = await this.ctx.database.get("channel_server", { cid }, ["sid"]);
|
|
541
566
|
return await this.ctx.database.get("server", rows.map((obj) => obj.sid));
|
|
542
567
|
}
|
|
543
568
|
/**
|
|
544
|
-
*
|
|
569
|
+
* 根据服务器ID获取服务器信息
|
|
570
|
+
* @param id - 服务器ID
|
|
571
|
+
* @returns 服务器信息,不存在则返回null
|
|
545
572
|
*/
|
|
546
573
|
async getServerById(id) {
|
|
547
574
|
const rows = await this.ctx.database.get(this.tableName, id);
|
|
@@ -549,6 +576,8 @@ var ServerService = class {
|
|
|
549
576
|
}
|
|
550
577
|
/**
|
|
551
578
|
* 根据名称查找服务器
|
|
579
|
+
* @param name - 服务器名称
|
|
580
|
+
* @returns 服务器信息,不存在则返回null
|
|
552
581
|
*/
|
|
553
582
|
async getServerByName(name13) {
|
|
554
583
|
const rows = await this.ctx.database.get(this.tableName, { name: name13 });
|
|
@@ -556,6 +585,8 @@ var ServerService = class {
|
|
|
556
585
|
}
|
|
557
586
|
/**
|
|
558
587
|
* 根据类型筛选服务器
|
|
588
|
+
* @param type - 服务器类型
|
|
589
|
+
* @returns 筛选后的服务器列表
|
|
559
590
|
*/
|
|
560
591
|
async getServersByType(type) {
|
|
561
592
|
const servers = await this.ctx.database.get(this.tableName, { type });
|
|
@@ -563,8 +594,8 @@ var ServerService = class {
|
|
|
563
594
|
}
|
|
564
595
|
/**
|
|
565
596
|
* 创建一个新的服务器记录并关联到用户
|
|
566
|
-
* @param serverData 要插入的数据
|
|
567
|
-
* @param uid
|
|
597
|
+
* @param serverData - 要插入的数据(不含ID)
|
|
598
|
+
* @param uid - 用户ID
|
|
568
599
|
* @returns 插入后的完整数据
|
|
569
600
|
*/
|
|
570
601
|
async createServerForUser(serverData, uid) {
|
|
@@ -574,8 +605,8 @@ var ServerService = class {
|
|
|
574
605
|
}
|
|
575
606
|
/**
|
|
576
607
|
* 创建一个新的服务器记录并关联到频道
|
|
577
|
-
* @param serverData 要插入的数据
|
|
578
|
-
* @param cid
|
|
608
|
+
* @param serverData - 要插入的数据(不含ID)
|
|
609
|
+
* @param cid - 频道ID
|
|
579
610
|
* @returns 插入后的完整数据
|
|
580
611
|
*/
|
|
581
612
|
async createServerForChannel(serverData, cid) {
|
|
@@ -585,15 +616,17 @@ var ServerService = class {
|
|
|
585
616
|
}
|
|
586
617
|
/**
|
|
587
618
|
* 更新服务器记录
|
|
588
|
-
* @param id 服务器
|
|
589
|
-
* @param partial 要更新的字段
|
|
619
|
+
* @param id - 服务器ID
|
|
620
|
+
* @param partial - 要更新的字段
|
|
621
|
+
* @returns 无返回值的Promise
|
|
590
622
|
*/
|
|
591
623
|
async updateServer(id, partial) {
|
|
592
624
|
await this.ctx.database.set(this.tableName, id, partial);
|
|
593
625
|
}
|
|
594
626
|
/**
|
|
595
627
|
* 删除服务器记录
|
|
596
|
-
* @param id 服务器
|
|
628
|
+
* @param id - 服务器ID
|
|
629
|
+
* @returns 无返回值的Promise
|
|
597
630
|
*/
|
|
598
631
|
async removeServer(id) {
|
|
599
632
|
await this.ctx.database.remove(this.tableName, id);
|
|
@@ -624,14 +657,41 @@ var ServerService = class {
|
|
|
624
657
|
}
|
|
625
658
|
}
|
|
626
659
|
}
|
|
660
|
+
/**
|
|
661
|
+
* 根据用户ID获取默认服务器
|
|
662
|
+
* @param uid - 用户ID
|
|
663
|
+
* @returns 用户设置的默认服务器,若不存在则返回null
|
|
664
|
+
*/
|
|
665
|
+
async getDefaultServerByUid(uid) {
|
|
666
|
+
const userRes = await this.ctx.database.get("user", { id: uid }, ["defaultServerId"]);
|
|
667
|
+
if (!userRes[0] || userRes[0].defaultServerId === void 0 || userRes[0].defaultServerId === 0) return null;
|
|
668
|
+
return await this.getServerById(userRes[0].defaultServerId);
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* 根据频道ID获取默认服务器
|
|
672
|
+
* @param platform - 平台标识
|
|
673
|
+
* @param cid - 频道ID
|
|
674
|
+
* @returns 频道设置的默认服务器,若不存在则返回null
|
|
675
|
+
*/
|
|
676
|
+
async getDefaultServerByCid(platform, cid) {
|
|
677
|
+
const channelRes = await this.ctx.database.getChannel(platform, cid, ["defaultServerId"]);
|
|
678
|
+
if (!channelRes || channelRes.defaultServerId === void 0 || channelRes.defaultServerId === 0) return null;
|
|
679
|
+
return await this.getServerById(channelRes.defaultServerId);
|
|
680
|
+
}
|
|
627
681
|
};
|
|
628
682
|
|
|
629
683
|
// src/core/commands/card.ts
|
|
630
684
|
function card(ctx, config) {
|
|
631
|
-
ctx.command("card").alias("卡片管理").userFields(["
|
|
685
|
+
ctx.command("card").alias("卡片管理").userFields(["id"]).channelFields(["id"]).action(async ({ session }) => {
|
|
632
686
|
const cardService = new CardService(ctx);
|
|
633
687
|
const serverService = new ServerService(ctx);
|
|
634
688
|
const userService = new UserService(ctx);
|
|
689
|
+
const defaultCard = await cardService.getDefaultCardByUid(session.user.id);
|
|
690
|
+
const defaultCardId = defaultCard ? defaultCard.id : 0;
|
|
691
|
+
const userDefaultServer = await serverService.getDefaultServerByUid(session.user.id);
|
|
692
|
+
const userDefaultServerId = userDefaultServer ? userDefaultServer.id : 0;
|
|
693
|
+
const channelDefaultServer = await serverService.getDefaultServerByCid(session.platform, session.channel.id);
|
|
694
|
+
const channelDefaultServerId = channelDefaultServer ? channelDefaultServer.id : 0;
|
|
635
695
|
return await showCardSelectMenu(
|
|
636
696
|
ctx,
|
|
637
697
|
session,
|
|
@@ -639,10 +699,10 @@ function card(ctx, config) {
|
|
|
639
699
|
serverService,
|
|
640
700
|
userService,
|
|
641
701
|
session.user.id,
|
|
642
|
-
|
|
643
|
-
|
|
702
|
+
defaultCardId,
|
|
703
|
+
userDefaultServerId,
|
|
644
704
|
session.channel.id,
|
|
645
|
-
|
|
705
|
+
channelDefaultServerId
|
|
646
706
|
);
|
|
647
707
|
});
|
|
648
708
|
}
|
|
@@ -793,31 +853,39 @@ var serverValues = ["asphyxia", "mao"];
|
|
|
793
853
|
|
|
794
854
|
// src/core/commands/server.ts
|
|
795
855
|
function server(ctx, config) {
|
|
796
|
-
ctx.command("server").alias("服务器管理").option("channel", "-c").userFields(["
|
|
856
|
+
ctx.command("server").alias("服务器管理").option("channel", "-c").userFields(["id"]).channelFields(["id"]).action(async ({ session, options }) => {
|
|
797
857
|
const serverService = new ServerService(ctx);
|
|
798
858
|
const userService = new UserService(ctx);
|
|
799
859
|
if (options.channel) {
|
|
800
860
|
if (!hasPermission(isGuildAdmin(session), isPluginAdmin(session, config))) return session.text(".no-auth");
|
|
861
|
+
const userDefaultServer2 = await serverService.getDefaultServerByUid(session.user.id);
|
|
862
|
+
const userDefaultServerId2 = userDefaultServer2 ? userDefaultServer2.id : 0;
|
|
863
|
+
const channelDefaultServer2 = await serverService.getDefaultServerByCid(session.platform, session.channel.id);
|
|
864
|
+
const channelDefaultServerId2 = channelDefaultServer2 ? channelDefaultServer2.id : 0;
|
|
801
865
|
return await showChannelServerSelectMenu(
|
|
802
866
|
ctx,
|
|
803
867
|
session,
|
|
804
868
|
serverService,
|
|
805
869
|
userService,
|
|
806
870
|
session.user.id,
|
|
807
|
-
|
|
871
|
+
userDefaultServerId2,
|
|
808
872
|
session.channel.id,
|
|
809
|
-
|
|
873
|
+
channelDefaultServerId2
|
|
810
874
|
);
|
|
811
875
|
}
|
|
876
|
+
const userDefaultServer = await serverService.getDefaultServerByUid(session.user.id);
|
|
877
|
+
const userDefaultServerId = userDefaultServer ? userDefaultServer.id : 0;
|
|
878
|
+
const channelDefaultServer = await serverService.getDefaultServerByCid(session.platform, session.channel.id);
|
|
879
|
+
const channelDefaultServerId = channelDefaultServer ? channelDefaultServer.id : 0;
|
|
812
880
|
return await showUserServerSelectMenu(
|
|
813
881
|
ctx,
|
|
814
882
|
session,
|
|
815
883
|
serverService,
|
|
816
884
|
userService,
|
|
817
885
|
session.user.id,
|
|
818
|
-
|
|
886
|
+
userDefaultServerId,
|
|
819
887
|
session.channel.id,
|
|
820
|
-
|
|
888
|
+
channelDefaultServerId
|
|
821
889
|
);
|
|
822
890
|
});
|
|
823
891
|
}
|
|
@@ -1193,6 +1261,9 @@ var Asphyxia = class {
|
|
|
1193
1261
|
supportedGames = ["sdvx", "iidx"];
|
|
1194
1262
|
gameServices = {};
|
|
1195
1263
|
logger = new import_koishi4.Logger("Noah-Asphyxia");
|
|
1264
|
+
/**
|
|
1265
|
+
* 初始化各个游戏服务实例
|
|
1266
|
+
*/
|
|
1196
1267
|
constructor() {
|
|
1197
1268
|
this.gameServices["sdvx"] = SDVXService.getInstance(this.logger);
|
|
1198
1269
|
this.gameServices["iidx"] = IIDXService.getInstance(this.logger);
|
|
@@ -1204,7 +1275,7 @@ var import_koishi5 = require("koishi");
|
|
|
1204
1275
|
|
|
1205
1276
|
// src/servers/utils/grade.ts
|
|
1206
1277
|
function getSDVXGrade(score) {
|
|
1207
|
-
if (score
|
|
1278
|
+
if (score >= 99e5) return "S";
|
|
1208
1279
|
if (score >= 98e5) return "AAA+";
|
|
1209
1280
|
if (score >= 97e5) return "AAA";
|
|
1210
1281
|
if (score >= 95e5) return "AA+";
|
|
@@ -1323,12 +1394,23 @@ var MusicService = class _MusicService {
|
|
|
1323
1394
|
constructor(config) {
|
|
1324
1395
|
this.sdvx_data_url = config.sdvx_data_url;
|
|
1325
1396
|
}
|
|
1397
|
+
/**
|
|
1398
|
+
* 获取 MusicService 实例
|
|
1399
|
+
* @param config - SDVX 配置对象
|
|
1400
|
+
* @returns MusicService 实例
|
|
1401
|
+
*/
|
|
1326
1402
|
static getInstance(config) {
|
|
1327
1403
|
if (!_MusicService.instance) {
|
|
1328
1404
|
_MusicService.instance = new _MusicService(config);
|
|
1329
1405
|
}
|
|
1330
1406
|
return _MusicService.instance;
|
|
1331
1407
|
}
|
|
1408
|
+
/**
|
|
1409
|
+
* 获取音乐信息
|
|
1410
|
+
* @param ctx - Koishi 上下文对象
|
|
1411
|
+
* @param musicIds - 音乐 ID 数组
|
|
1412
|
+
* @returns 音乐信息数组
|
|
1413
|
+
*/
|
|
1332
1414
|
async getMusic(ctx, musicIds) {
|
|
1333
1415
|
try {
|
|
1334
1416
|
const response = await ctx.http.post(`/music`, {
|
|
@@ -1621,6 +1703,9 @@ var Mao = class {
|
|
|
1621
1703
|
supportedGames = ["sdvx"];
|
|
1622
1704
|
gameServices = {};
|
|
1623
1705
|
logger = new import_koishi5.Logger("Noah-Mao");
|
|
1706
|
+
/**
|
|
1707
|
+
* 初始化SDVX游戏服务实例
|
|
1708
|
+
*/
|
|
1624
1709
|
constructor() {
|
|
1625
1710
|
this.gameServices["sdvx"] = SDVXService2.getInstance(this.logger);
|
|
1626
1711
|
}
|
|
@@ -1632,6 +1717,12 @@ var ServerFactory = class {
|
|
|
1632
1717
|
__name(this, "ServerFactory");
|
|
1633
1718
|
}
|
|
1634
1719
|
serverInstances = /* @__PURE__ */ new Map();
|
|
1720
|
+
/**
|
|
1721
|
+
* 根据服务器类型获取服务器实例,如果不存在则创建新实例
|
|
1722
|
+
* @param serverType - 服务器类型
|
|
1723
|
+
* @returns 对应的服务器实例
|
|
1724
|
+
* @throws 当请求不支持的服务器类型时抛出异常
|
|
1725
|
+
*/
|
|
1635
1726
|
getServer(serverType) {
|
|
1636
1727
|
if (!this.serverInstances.has(serverType)) {
|
|
1637
1728
|
let serverInstance;
|
|
@@ -1662,15 +1753,30 @@ var ServerManager = class _ServerManager {
|
|
|
1662
1753
|
constructor() {
|
|
1663
1754
|
this.factory = new ServerFactory();
|
|
1664
1755
|
}
|
|
1756
|
+
/**
|
|
1757
|
+
* 获取服务器管理器实例
|
|
1758
|
+
* @returns 服务器管理器的唯一实例
|
|
1759
|
+
*/
|
|
1665
1760
|
static getInstance() {
|
|
1666
1761
|
if (!_ServerManager.instance) {
|
|
1667
1762
|
_ServerManager.instance = new _ServerManager();
|
|
1668
1763
|
}
|
|
1669
1764
|
return _ServerManager.instance;
|
|
1670
1765
|
}
|
|
1766
|
+
/**
|
|
1767
|
+
* 根据服务器类型获取对应的服务器实例
|
|
1768
|
+
* @param serverType - 服务器类型
|
|
1769
|
+
* @returns 对应的服务器实例
|
|
1770
|
+
*/
|
|
1671
1771
|
getServer(serverType) {
|
|
1672
1772
|
return this.factory.getServer(serverType);
|
|
1673
1773
|
}
|
|
1774
|
+
/**
|
|
1775
|
+
* 根据服务器类型和游戏类型获取对应的游戏服务实例
|
|
1776
|
+
* @param serverType - 服务器类型
|
|
1777
|
+
* @param gameType - 游戏类型
|
|
1778
|
+
* @returns 对应的游戏服务实例
|
|
1779
|
+
*/
|
|
1674
1780
|
getGameService(serverType, gameType) {
|
|
1675
1781
|
const server2 = this.factory.getServer(serverType);
|
|
1676
1782
|
return server2.gameServices[gameType];
|
|
@@ -1688,6 +1794,10 @@ var ScoreService = class _ScoreService {
|
|
|
1688
1794
|
static instance;
|
|
1689
1795
|
constructor() {
|
|
1690
1796
|
}
|
|
1797
|
+
/**
|
|
1798
|
+
* 获取 ScoreService 实例
|
|
1799
|
+
* @returns ScoreService 实例
|
|
1800
|
+
*/
|
|
1691
1801
|
static getInstance() {
|
|
1692
1802
|
if (!_ScoreService.instance) {
|
|
1693
1803
|
_ScoreService.instance = new _ScoreService();
|
|
@@ -1695,17 +1805,17 @@ var ScoreService = class _ScoreService {
|
|
|
1695
1805
|
return _ScoreService.instance;
|
|
1696
1806
|
}
|
|
1697
1807
|
/**
|
|
1698
|
-
*
|
|
1699
|
-
* @param scores
|
|
1700
|
-
* @returns
|
|
1808
|
+
* 按 Volforce 降序排序分数
|
|
1809
|
+
* @param scores - 待排序的 SDVX 分数数组
|
|
1810
|
+
* @returns 按 Volforce 降序排序的新数组
|
|
1701
1811
|
*/
|
|
1702
1812
|
sortByVolforce(scores) {
|
|
1703
1813
|
return [...scores].sort((a, b) => b.extra.volforce - a.extra.volforce);
|
|
1704
1814
|
}
|
|
1705
1815
|
/**
|
|
1706
|
-
*
|
|
1707
|
-
* @param scores
|
|
1708
|
-
* @returns
|
|
1816
|
+
* 获取前 50 名分数(包括并列)
|
|
1817
|
+
* @param scores - 待处理的 SDVX 分数数组
|
|
1818
|
+
* @returns 包含最高 Volforce 值的分数数组(如果存在并列,可能超过 50 个)
|
|
1709
1819
|
*/
|
|
1710
1820
|
getBest50(scores) {
|
|
1711
1821
|
const sortedScores = this.sortByVolforce(scores);
|
|
@@ -1736,10 +1846,10 @@ var BaseDrawer = class {
|
|
|
1736
1846
|
__name(this, "BaseDrawer");
|
|
1737
1847
|
}
|
|
1738
1848
|
/**
|
|
1739
|
-
*
|
|
1740
|
-
* @param canvas
|
|
1741
|
-
* @param compression
|
|
1742
|
-
* @returns
|
|
1849
|
+
* 压缩图片缓冲区
|
|
1850
|
+
* @param canvas - 要压缩的canvas对象
|
|
1851
|
+
* @param compression - 压缩选项
|
|
1852
|
+
* @returns 压缩后的缓冲区
|
|
1743
1853
|
*/
|
|
1744
1854
|
async compressImage(canvas, compression) {
|
|
1745
1855
|
if (!compression) {
|
|
@@ -1750,7 +1860,7 @@ var BaseDrawer = class {
|
|
|
1750
1860
|
const pngBuffer = await canvas.toBuffer("png");
|
|
1751
1861
|
return (0, import_sharp.default)(pngBuffer).png({
|
|
1752
1862
|
compressionLevel: 9,
|
|
1753
|
-
//
|
|
1863
|
+
// 最大压缩
|
|
1754
1864
|
adaptiveFiltering: true,
|
|
1755
1865
|
progressive: true
|
|
1756
1866
|
}).toBuffer();
|
|
@@ -1775,10 +1885,10 @@ var CoreDrawer = class extends BaseDrawer {
|
|
|
1775
1885
|
__name(this, "CoreDrawer");
|
|
1776
1886
|
}
|
|
1777
1887
|
/**
|
|
1778
|
-
*
|
|
1779
|
-
* @param options
|
|
1780
|
-
* @param compression
|
|
1781
|
-
* @returns
|
|
1888
|
+
* 生成通用图像
|
|
1889
|
+
* @param options - 图像生成配置选项
|
|
1890
|
+
* @param compression - 压缩选项
|
|
1891
|
+
* @returns 包含图像数据的Buffer
|
|
1782
1892
|
*/
|
|
1783
1893
|
async generateImage(options, compression) {
|
|
1784
1894
|
const { Canvas, loadImage } = this.ctx.skia;
|
|
@@ -1833,10 +1943,10 @@ var SDVXDrawer = class extends BaseDrawer {
|
|
|
1833
1943
|
}
|
|
1834
1944
|
// TODO: 添加最近图片的生成
|
|
1835
1945
|
/**
|
|
1836
|
-
*
|
|
1837
|
-
* @param options
|
|
1838
|
-
* @param compression
|
|
1839
|
-
* @returns
|
|
1946
|
+
* 生成SDVX最近成绩图像
|
|
1947
|
+
* @param options - 图像生成配置选项
|
|
1948
|
+
* @param compression - 压缩选项
|
|
1949
|
+
* @returns 包含图像数据的Buffer
|
|
1840
1950
|
*/
|
|
1841
1951
|
async generateRecentImage(options, compression) {
|
|
1842
1952
|
const { Canvas, loadImage, FontLibrary } = this.ctx.skia;
|
|
@@ -1853,10 +1963,10 @@ var SDVXDrawer = class extends BaseDrawer {
|
|
|
1853
1963
|
return this.compressImage(canvas, compression);
|
|
1854
1964
|
}
|
|
1855
1965
|
/**
|
|
1856
|
-
*
|
|
1857
|
-
* @param options
|
|
1858
|
-
* @param compression
|
|
1859
|
-
* @returns
|
|
1966
|
+
* 生成SDVX Volforce图像
|
|
1967
|
+
* @param options - 图像生成配置选项
|
|
1968
|
+
* @param compression - 压缩选项
|
|
1969
|
+
* @returns 包含图像数据的Buffer
|
|
1860
1970
|
*/
|
|
1861
1971
|
async generateVFImage(options, compression) {
|
|
1862
1972
|
const { Canvas, loadImage, FontLibrary } = this.ctx.skia;
|
|
@@ -1915,7 +2025,12 @@ var SDVXDrawer = class extends BaseDrawer {
|
|
|
1915
2025
|
return this.compressImage(canvas, compression);
|
|
1916
2026
|
}
|
|
1917
2027
|
/**
|
|
1918
|
-
*
|
|
2028
|
+
* 在画布上绘制成绩卡片
|
|
2029
|
+
* @param ctx - Canvas上下文
|
|
2030
|
+
* @param scores - 成绩数组
|
|
2031
|
+
* @param cardBgImage - 卡片背景图像
|
|
2032
|
+
* @param loadImage - 图像加载函数
|
|
2033
|
+
* @param config - SDVX配置
|
|
1919
2034
|
*/
|
|
1920
2035
|
async drawScoreCards(ctx, scores, cardBgImage, loadImage, config) {
|
|
1921
2036
|
if (scores.length === 0) return;
|
|
@@ -2282,10 +2397,10 @@ var IIDXDrawer = class extends BaseDrawer {
|
|
|
2282
2397
|
__name(this, "IIDXDrawer");
|
|
2283
2398
|
}
|
|
2284
2399
|
/**
|
|
2285
|
-
*
|
|
2286
|
-
* @param options
|
|
2287
|
-
* @param compression
|
|
2288
|
-
* @returns
|
|
2400
|
+
* 生成IIDX游戏数据图像
|
|
2401
|
+
* @param options - 图像生成配置选项
|
|
2402
|
+
* @param compression - 压缩选项
|
|
2403
|
+
* @returns 包含图像数据的Buffer
|
|
2289
2404
|
*/
|
|
2290
2405
|
async generateImage(options, compression) {
|
|
2291
2406
|
const { Canvas, loadImage } = this.ctx.skia;
|
|
@@ -2317,7 +2432,13 @@ var IIDXDrawer = class extends BaseDrawer {
|
|
|
2317
2432
|
return this.compressImage(canvas, compression);
|
|
2318
2433
|
}
|
|
2319
2434
|
/**
|
|
2320
|
-
*
|
|
2435
|
+
* 绘制段位信息
|
|
2436
|
+
* @param ctx - Canvas上下文
|
|
2437
|
+
* @param centerX - 中心X坐标
|
|
2438
|
+
* @param y - 起始Y坐标
|
|
2439
|
+
* @param sp_dan - sp 段位
|
|
2440
|
+
* @param dp_dan - dp 段位
|
|
2441
|
+
* @param textColor - 文字颜色
|
|
2321
2442
|
*/
|
|
2322
2443
|
drawRankingInfo(ctx, centerX, y, sp_dan, dp_dan, textColor) {
|
|
2323
2444
|
ctx.fillStyle = textColor;
|
|
@@ -2342,6 +2463,12 @@ var DrawerFactory = class {
|
|
|
2342
2463
|
__name(this, "DrawerFactory");
|
|
2343
2464
|
}
|
|
2344
2465
|
drawerInstances = /* @__PURE__ */ new Map();
|
|
2466
|
+
/**
|
|
2467
|
+
* 根据绘图类型获取绘图实例,如果不存在则创建新实例
|
|
2468
|
+
* @param drawerType - 绘图类型(游戏类型或核心类型)
|
|
2469
|
+
* @returns 对应的绘图实例
|
|
2470
|
+
* @throws 当请求不支持的绘图类型时抛出异常
|
|
2471
|
+
*/
|
|
2345
2472
|
getDrawer(drawerType) {
|
|
2346
2473
|
if (!this.drawerInstances.has(drawerType)) {
|
|
2347
2474
|
let drawerInstance;
|
|
@@ -2377,15 +2504,25 @@ var DrawerManager = class _DrawerManager {
|
|
|
2377
2504
|
this.factory = new DrawerFactory(ctx);
|
|
2378
2505
|
this.logger = new import_koishi6.Logger("Noah-Drawer");
|
|
2379
2506
|
}
|
|
2507
|
+
/**
|
|
2508
|
+
* 获取绘图管理器实例
|
|
2509
|
+
* @param ctx - Koishi上下文
|
|
2510
|
+
* @returns 绘图管理器的唯一实例
|
|
2511
|
+
*/
|
|
2380
2512
|
static getInstance(ctx) {
|
|
2381
2513
|
if (!_DrawerManager.instance) {
|
|
2382
2514
|
_DrawerManager.instance = new _DrawerManager(ctx);
|
|
2383
2515
|
}
|
|
2384
2516
|
return _DrawerManager.instance;
|
|
2385
2517
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2518
|
+
/**
|
|
2519
|
+
* 根据插件类型获取对应的绘图实例
|
|
2520
|
+
* @param pluginType - 插件类型
|
|
2521
|
+
* @returns 对应的绘图实例
|
|
2522
|
+
*/
|
|
2523
|
+
getDrawer(pluginType) {
|
|
2524
|
+
this.logger.info(`Getting drawer for ${pluginType}`);
|
|
2525
|
+
return this.factory.getDrawer(pluginType);
|
|
2389
2526
|
}
|
|
2390
2527
|
};
|
|
2391
2528
|
function apply6(ctx, config) {
|
|
@@ -2408,12 +2545,14 @@ function vf(ctx, config) {
|
|
|
2408
2545
|
if (serverRes.length === 0) return session.text(".server-not-found");
|
|
2409
2546
|
let cardCode = "";
|
|
2410
2547
|
if (!options.card) {
|
|
2411
|
-
const
|
|
2412
|
-
|
|
2548
|
+
const defaultCard = await cardService.getDefaultCardByUid(session.user.id);
|
|
2549
|
+
if (!defaultCard) return session.text(".card-not-found");
|
|
2550
|
+
cardCode = defaultCard.code;
|
|
2413
2551
|
} else {
|
|
2414
2552
|
let cardListMsg = "";
|
|
2415
2553
|
for (let i = 0; i < userCards.length; i++) {
|
|
2416
|
-
|
|
2554
|
+
const defaultCard = await cardService.getDefaultCardByUid(session.user.id);
|
|
2555
|
+
if (defaultCard && userCards[i].id === defaultCard.id) {
|
|
2417
2556
|
cardListMsg += `<p>${i + 1}. ${userCards[i].name} < 默认卡片</p>`;
|
|
2418
2557
|
} else {
|
|
2419
2558
|
cardListMsg += `<p>${i + 1}. ${userCards[i].name}</p>`;
|
|
@@ -2433,9 +2572,15 @@ function vf(ctx, config) {
|
|
|
2433
2572
|
const card2 = await cardService.getCardByCode(cardCode);
|
|
2434
2573
|
let server2;
|
|
2435
2574
|
if (card2.defaultServerId != void 0 && card2.defaultServerId != 0) server2 = await serverService.getServerById(card2.defaultServerId);
|
|
2436
|
-
else
|
|
2437
|
-
|
|
2438
|
-
|
|
2575
|
+
else {
|
|
2576
|
+
const channelDefaultServer = await serverService.getDefaultServerByCid(session.platform, session.channel.id);
|
|
2577
|
+
if (channelDefaultServer) server2 = channelDefaultServer;
|
|
2578
|
+
else {
|
|
2579
|
+
const userDefaultServer = await serverService.getDefaultServerByUid(session.user.id);
|
|
2580
|
+
if (userDefaultServer) server2 = userDefaultServer;
|
|
2581
|
+
else return session.text(".server-not-found");
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2439
2584
|
const serverManager = ServerManager.getInstance();
|
|
2440
2585
|
const sdvxService = serverManager.getGameService(server2.type, "sdvx");
|
|
2441
2586
|
const scoreService = ScoreService.getInstance();
|