koishi-plugin-noah 2.3.3 → 2.3.5
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/core/utils/server.d.ts +7 -0
- package/lib/index.cjs +57 -64
- package/package.json +77 -77
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
|
+
import { CardService } from '../services/card-service';
|
|
2
3
|
import { ServerService } from '../services/server-service';
|
|
3
4
|
import { UserService } from '../services/user-service';
|
|
5
|
+
import { Card, Server } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the server for a given card, with fallback to channel/user defaults.
|
|
8
|
+
* If the card references a deleted server, cleans up the stale reference automatically.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveServerForCard(card: Card, cardService: CardService, serverService: ServerService, uid: number, platform: string, channelId: string | null): Promise<Server | null>;
|
|
4
11
|
/**
|
|
5
12
|
* Ensure the user has an Official (KONAMI) server and return its id.
|
|
6
13
|
* Creates one with the configured support URL when missing.
|
package/lib/index.cjs
CHANGED
|
@@ -644,18 +644,20 @@ var ServerService = class {
|
|
|
644
644
|
if (channelServerRes.length > 0) {
|
|
645
645
|
await this.ctx.database.set(
|
|
646
646
|
"channel",
|
|
647
|
-
{ id: channel.id },
|
|
647
|
+
{ id: channel.id, platform: channel.platform },
|
|
648
648
|
{ defaultServerId: channelServerRes[0].sid }
|
|
649
649
|
);
|
|
650
650
|
} else {
|
|
651
|
-
await this.ctx.database.set(
|
|
651
|
+
await this.ctx.database.set(
|
|
652
|
+
"channel",
|
|
653
|
+
{ id: channel.id, platform: channel.platform },
|
|
654
|
+
{ defaultServerId: 0 }
|
|
655
|
+
);
|
|
652
656
|
}
|
|
653
657
|
}
|
|
654
658
|
const cardRes = await this.ctx.database.get("card", { defaultServerId: id });
|
|
655
659
|
for (const card2 of cardRes) {
|
|
656
|
-
|
|
657
|
-
await this.ctx.database.set("card", { id: card2.id }, { defaultServerId: 0 });
|
|
658
|
-
}
|
|
660
|
+
await this.ctx.database.set("card", { id: card2.id }, { defaultServerId: 0 });
|
|
659
661
|
}
|
|
660
662
|
}
|
|
661
663
|
/**
|
|
@@ -997,6 +999,19 @@ function formatCardInfo(data) {
|
|
|
997
999
|
__name(formatCardInfo, "formatCardInfo");
|
|
998
1000
|
|
|
999
1001
|
// src/core/utils/server.ts
|
|
1002
|
+
async function resolveServerForCard(card2, cardService, serverService, uid, platform, channelId) {
|
|
1003
|
+
if (card2.defaultServerId != void 0 && card2.defaultServerId != 0) {
|
|
1004
|
+
const cardServer = await serverService.getServerById(card2.defaultServerId);
|
|
1005
|
+
if (cardServer) return cardServer;
|
|
1006
|
+
await cardService.updateCard(card2.id, { defaultServerId: 0 });
|
|
1007
|
+
}
|
|
1008
|
+
if (channelId) {
|
|
1009
|
+
const channelDefault = await serverService.getDefaultServerByCid(platform, channelId);
|
|
1010
|
+
if (channelDefault) return channelDefault;
|
|
1011
|
+
}
|
|
1012
|
+
return await serverService.getDefaultServerByUid(uid);
|
|
1013
|
+
}
|
|
1014
|
+
__name(resolveServerForCard, "resolveServerForCard");
|
|
1000
1015
|
async function ensureOfficialServerForUser(ctx, serverService, userService, uid, officialSupportUrl) {
|
|
1001
1016
|
const userServers = await serverService.getServersByUid(uid);
|
|
1002
1017
|
const existingOfficial = userServers.find((server3) => server3.type === "official");
|
|
@@ -4775,22 +4790,24 @@ var MaoSDVXService = class _MaoSDVXService {
|
|
|
4775
4790
|
gradeToNum(grade) {
|
|
4776
4791
|
switch (grade) {
|
|
4777
4792
|
case "S":
|
|
4778
|
-
return
|
|
4793
|
+
return 10;
|
|
4779
4794
|
case "AAA+":
|
|
4780
|
-
return
|
|
4795
|
+
return 9;
|
|
4781
4796
|
case "AAA":
|
|
4782
|
-
return
|
|
4797
|
+
return 8;
|
|
4783
4798
|
case "AA+":
|
|
4784
|
-
return
|
|
4799
|
+
return 7;
|
|
4785
4800
|
case "AA":
|
|
4786
|
-
return
|
|
4801
|
+
return 6;
|
|
4787
4802
|
case "A+":
|
|
4788
|
-
return
|
|
4803
|
+
return 5;
|
|
4789
4804
|
case "A":
|
|
4790
|
-
return
|
|
4805
|
+
return 4;
|
|
4791
4806
|
case "B":
|
|
4792
|
-
return
|
|
4807
|
+
return 3;
|
|
4793
4808
|
case "C":
|
|
4809
|
+
return 2;
|
|
4810
|
+
case "D":
|
|
4794
4811
|
return 1;
|
|
4795
4812
|
default:
|
|
4796
4813
|
return 0;
|
|
@@ -5841,23 +5858,15 @@ function radar(ctx, config, logger5) {
|
|
|
5841
5858
|
const defaultCard = await cardService.getDefaultCardByUid(session.user.id);
|
|
5842
5859
|
if (!defaultCard) return session.text(".card-not-found");
|
|
5843
5860
|
const card2 = await cardService.getCardByCode(defaultCard.code);
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
else {
|
|
5854
|
-
const userDefaultServer = await serverService.getDefaultServerByUid(
|
|
5855
|
-
session.user.id
|
|
5856
|
-
);
|
|
5857
|
-
if (userDefaultServer) server2 = userDefaultServer;
|
|
5858
|
-
else return session.text(".server-not-found");
|
|
5859
|
-
}
|
|
5860
|
-
}
|
|
5861
|
+
const server2 = await resolveServerForCard(
|
|
5862
|
+
card2,
|
|
5863
|
+
cardService,
|
|
5864
|
+
serverService,
|
|
5865
|
+
session.user.id,
|
|
5866
|
+
session.platform,
|
|
5867
|
+
atGuild ? session.channel.id : null
|
|
5868
|
+
);
|
|
5869
|
+
if (!server2) return session.text(".server-not-found");
|
|
5861
5870
|
const serverManager = ServerManager.getInstance();
|
|
5862
5871
|
const sdvxService = serverManager.getGameService(server2.type, "sdvx");
|
|
5863
5872
|
const scoreService = ScoreService.getInstance();
|
|
@@ -5932,23 +5941,15 @@ function recent(ctx, config, logger5) {
|
|
|
5932
5941
|
cardCode = userCards[selectNum - 1].code;
|
|
5933
5942
|
}
|
|
5934
5943
|
const card2 = await cardService.getCardByCode(cardCode);
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
else {
|
|
5945
|
-
const userDefaultServer = await serverService.getDefaultServerByUid(
|
|
5946
|
-
session.user.id
|
|
5947
|
-
);
|
|
5948
|
-
if (userDefaultServer) server2 = userDefaultServer;
|
|
5949
|
-
else return session.text(".server-not-found");
|
|
5950
|
-
}
|
|
5951
|
-
}
|
|
5944
|
+
const server2 = await resolveServerForCard(
|
|
5945
|
+
card2,
|
|
5946
|
+
cardService,
|
|
5947
|
+
serverService,
|
|
5948
|
+
session.user.id,
|
|
5949
|
+
session.platform,
|
|
5950
|
+
atGuild ? session.channel.id : null
|
|
5951
|
+
);
|
|
5952
|
+
if (!server2) return session.text(".server-not-found");
|
|
5952
5953
|
const serverManager = ServerManager.getInstance();
|
|
5953
5954
|
const sdvxService = serverManager.getGameService(server2.type, "sdvx");
|
|
5954
5955
|
try {
|
|
@@ -6277,23 +6278,15 @@ function vf(ctx, config, logger5) {
|
|
|
6277
6278
|
cardCode = userCards[selectNum - 1].code;
|
|
6278
6279
|
}
|
|
6279
6280
|
const card2 = await cardService.getCardByCode(cardCode);
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
else {
|
|
6290
|
-
const userDefaultServer = await serverService.getDefaultServerByUid(
|
|
6291
|
-
session.user.id
|
|
6292
|
-
);
|
|
6293
|
-
if (userDefaultServer) server2 = userDefaultServer;
|
|
6294
|
-
else return session.text(".server-not-found");
|
|
6295
|
-
}
|
|
6296
|
-
}
|
|
6281
|
+
const server2 = await resolveServerForCard(
|
|
6282
|
+
card2,
|
|
6283
|
+
cardService,
|
|
6284
|
+
serverService,
|
|
6285
|
+
session.user.id,
|
|
6286
|
+
session.platform,
|
|
6287
|
+
atGuild ? session.channel.id : null
|
|
6288
|
+
);
|
|
6289
|
+
if (!server2) return session.text(".server-not-found");
|
|
6297
6290
|
const serverManager = ServerManager.getInstance();
|
|
6298
6291
|
const sdvxService = serverManager.getGameService(server2.type, "sdvx");
|
|
6299
6292
|
const scoreService = ScoreService.getInstance();
|
package/package.json
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
"name": "koishi-plugin-noah",
|
|
3
|
+
"version": "2.3.5",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"Logthm <logthm@outlook.com>"
|
|
6
|
+
],
|
|
7
|
+
"homepage": "https://docs.logthm.cn/noah",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.cjs",
|
|
10
|
+
"typings": "lib/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"chatbot",
|
|
18
|
+
"koishi",
|
|
19
|
+
"plugin"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"koishi": "^4.18.11"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"adm-zip": "^0.5.17",
|
|
26
|
+
"bwip-js": "^4.10.1",
|
|
27
|
+
"javascript-barcode-reader": "^0.6.9",
|
|
28
|
+
"koishi-plugin-adapter-onebot": "^6.9.3",
|
|
29
|
+
"sharp": "^0.33.5",
|
|
30
|
+
"xml2js": "^0.6.2"
|
|
31
|
+
},
|
|
32
|
+
"koishi": {
|
|
33
|
+
"description": {
|
|
34
|
+
"en": "A tool bot for arcade music games",
|
|
35
|
+
"zh": "街机音游工具机器人"
|
|
31
36
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"service": {
|
|
38
|
-
"required": [
|
|
39
|
-
"database",
|
|
40
|
-
"skia"
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
"locales": [
|
|
44
|
-
"en",
|
|
45
|
-
"zh"
|
|
46
|
-
]
|
|
37
|
+
"service": {
|
|
38
|
+
"required": [
|
|
39
|
+
"database",
|
|
40
|
+
"skia"
|
|
41
|
+
]
|
|
47
42
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"prettier --write"
|
|
77
|
-
],
|
|
78
|
-
"*.{css,md,json}": [
|
|
79
|
-
"prettier --write"
|
|
80
|
-
]
|
|
43
|
+
"locales": [
|
|
44
|
+
"en",
|
|
45
|
+
"zh"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@haixee/eslint-config": "^2.3.2",
|
|
50
|
+
"@koishijs/plugin-adapter-discord": "^4.6.0",
|
|
51
|
+
"@ltxhhz/koishi-plugin-skia-canvas": "^0.0.8",
|
|
52
|
+
"@types/adm-zip": "^0",
|
|
53
|
+
"@types/xml2js": "^0",
|
|
54
|
+
"eslint": "^9.39.4",
|
|
55
|
+
"eslint-config-prettier": "^10.1.8",
|
|
56
|
+
"eslint-import-resolver-typescript": "^3.10.1",
|
|
57
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
58
|
+
"husky": "^9.1.7",
|
|
59
|
+
"koishi": "^4.18.11",
|
|
60
|
+
"lint-staged": "^16.4.0",
|
|
61
|
+
"prettier": "^3.8.3",
|
|
62
|
+
"yml-register": "^1.2.5"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "eslint --ext .js,.ts,.tsx src/",
|
|
66
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx,json,css,md}\""
|
|
67
|
+
},
|
|
68
|
+
"husky": {
|
|
69
|
+
"hooks": {
|
|
70
|
+
"pre-commit": "lint-staged"
|
|
81
71
|
}
|
|
72
|
+
},
|
|
73
|
+
"lint-staged": {
|
|
74
|
+
"*.{js,ts,tsx}": [
|
|
75
|
+
"eslint --fix",
|
|
76
|
+
"prettier --write"
|
|
77
|
+
],
|
|
78
|
+
"*.{css,md,json}": [
|
|
79
|
+
"prettier --write"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
82
|
}
|