koishi-plugin-w-ygo 0.0.2 → 0.0.4
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/apis.d.ts +2 -3
- package/lib/index.d.ts +5 -1
- package/lib/index.js +33 -21
- package/package.json +5 -5
- package/readme.md +3 -0
package/lib/apis.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare namespace
|
|
1
|
+
export declare namespace API {
|
|
2
2
|
const ygocdb: (query: {
|
|
3
3
|
search: string;
|
|
4
4
|
}) => string;
|
|
@@ -65,7 +65,6 @@ export declare namespace APIs {
|
|
|
65
65
|
amount: number;
|
|
66
66
|
type: string;
|
|
67
67
|
};
|
|
68
|
-
const showMdmObtain: (obtain: MdmObtain) => string;
|
|
69
68
|
type MdmCard = {
|
|
70
69
|
_id: string;
|
|
71
70
|
gameId: string | number;
|
|
@@ -94,7 +93,7 @@ export declare namespace APIs {
|
|
|
94
93
|
deckTypes: string[];
|
|
95
94
|
};
|
|
96
95
|
type MdmCards = MdmCard[];
|
|
97
|
-
const
|
|
96
|
+
const cardImage: (template: string, query: {
|
|
98
97
|
id: number;
|
|
99
98
|
}) => string;
|
|
100
99
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export declare const name = "w-ygo";
|
|
3
3
|
export interface Config {
|
|
4
|
+
retry: number;
|
|
5
|
+
mdmDefault: boolean;
|
|
6
|
+
showExpiredPacks: boolean;
|
|
7
|
+
cardImageUrl: string;
|
|
4
8
|
}
|
|
5
9
|
export declare const Config: Schema<Config>;
|
|
6
|
-
export declare function apply(ctx: Context): void;
|
|
10
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -28,11 +28,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
28
|
var import_koishi = require("koishi");
|
|
29
29
|
|
|
30
30
|
// src/apis.ts
|
|
31
|
-
var
|
|
32
|
-
((
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
var API;
|
|
32
|
+
((API2) => {
|
|
33
|
+
API2.ygocdb = /* @__PURE__ */ __name((query) => `https://ygocdb.com/api/v0/?search=${encodeURIComponent(query.search)}`, "ygocdb");
|
|
34
|
+
API2.mdmcards = /* @__PURE__ */ __name((query) => `https://www.masterduelmeta.com/api/v1/cards?search=${encodeURIComponent(query.name)}`, "mdmcards");
|
|
35
|
+
API2.showMdmBanStatus = /* @__PURE__ */ __name((banStatus) => {
|
|
36
36
|
if (!banStatus) return "无";
|
|
37
37
|
switch (banStatus) {
|
|
38
38
|
case "Limited 2":
|
|
@@ -43,25 +43,34 @@ var APIs;
|
|
|
43
43
|
return "禁止";
|
|
44
44
|
}
|
|
45
45
|
}, "showMdmBanStatus");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return `${obtain.source.name}${expired ? "" : " (过期) "}`;
|
|
49
|
-
}, "showMdmObtain");
|
|
50
|
-
APIs2.momobako = /* @__PURE__ */ __name((query) => `https://cdn.233.momobako.com/ygopro/pics/${query.id}.jpg`, "momobako");
|
|
51
|
-
})(APIs || (APIs = {}));
|
|
46
|
+
API2.cardImage = /* @__PURE__ */ __name((template, query) => template.replaceAll("{id}", String(query.id)), "cardImage");
|
|
47
|
+
})(API || (API = {}));
|
|
52
48
|
|
|
53
49
|
// src/index.tsx
|
|
54
50
|
var import_jsx_runtime = require("@satorijs/element/jsx-runtime");
|
|
55
51
|
var name = "w-ygo";
|
|
56
|
-
var Config = import_koishi.Schema.object({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
var Config = import_koishi.Schema.object({
|
|
53
|
+
retry: import_koishi.Schema.number().default(3).description("API 请求失败时的重试次数"),
|
|
54
|
+
mdmDefault: import_koishi.Schema.boolean().default(false).description("是否默认启用 Master Duel Meta 信息"),
|
|
55
|
+
showExpiredPacks: import_koishi.Schema.boolean().default(false).description("是否显示过期的 MD 卡包"),
|
|
56
|
+
cardImageUrl: import_koishi.Schema.string().default("https://cdn.233.momobako.com/ygoimg/sc/{id}.webp").description("卡图 URL 模板,使用 {id} 表示卡片密码")
|
|
57
|
+
});
|
|
58
|
+
function apply(ctx, config) {
|
|
59
|
+
const get = /* @__PURE__ */ __name(async (url, { retry = config.retry } = {}) => {
|
|
60
|
+
try {
|
|
61
|
+
return await ctx.http.get(url);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (retry > 0) return get(url, { retry: retry - 1 });
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}, "get");
|
|
67
|
+
ctx.command("ygo <search:text>", "通过 ygocdb.com 搜索游戏王卡片").option("mdm", "-m 从 Master Duel Meta 获取额外信息(会消耗更多时间)", { fallback: config.mdmDefault }).option("mdm", "-M", { value: false }).action(async ({ session, options }, search) => {
|
|
68
|
+
const { result: cards } = await get(API.ygocdb({ search }));
|
|
60
69
|
if (!cards.length) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "未找到相关卡片" });
|
|
61
70
|
const [card] = cards;
|
|
62
71
|
let mdminfo = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "从 MDM 获取信息失败" });
|
|
63
72
|
if (options.mdm) {
|
|
64
|
-
const mdmcards = await
|
|
73
|
+
const mdmcards = await get(API.mdmcards({ name: card.en_name }));
|
|
65
74
|
const gameId = String(card.cid);
|
|
66
75
|
const mdmcard = mdmcards.find((it) => String(it.gameId) === gameId);
|
|
67
76
|
if (mdmcard) {
|
|
@@ -72,26 +81,29 @@ function apply(ctx) {
|
|
|
72
81
|
] }),
|
|
73
82
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
74
83
|
"[MD 禁限] ",
|
|
75
|
-
|
|
84
|
+
API.showMdmBanStatus(mdmcard.banStatus)
|
|
76
85
|
] }),
|
|
77
86
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
78
87
|
"[OCG 禁限] ",
|
|
79
|
-
|
|
88
|
+
API.showMdmBanStatus(mdmcard.ocgBanStatus)
|
|
80
89
|
] }),
|
|
81
90
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
82
91
|
"[TCG 禁限] ",
|
|
83
|
-
|
|
92
|
+
API.showMdmBanStatus(mdmcard.tcgBanStatus)
|
|
84
93
|
] }),
|
|
85
94
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
86
95
|
"[MD 卡包] ",
|
|
87
|
-
mdmcard.obtain.map(
|
|
96
|
+
mdmcard.obtain.map((it) => {
|
|
97
|
+
const expired = it.source.expires && new Date(it.source.expires) < /* @__PURE__ */ new Date();
|
|
98
|
+
return { ...it, expired };
|
|
99
|
+
}).filter((it) => !it.expired || config.showExpiredPacks).sort((it) => +it.expired).map((obtain) => `${obtain.source.name}${obtain.expired ? " (过期)" : ""}`).join(", ") || "无"
|
|
88
100
|
] })
|
|
89
101
|
] });
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
session.send(/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("message", { forward: true, children: [
|
|
93
105
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("message", { children: [
|
|
94
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src:
|
|
106
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: API.cardImage(config.cardImageUrl, { id: card.id }), alt: card.en_name }),
|
|
95
107
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
96
108
|
"[MD 卡名] ",
|
|
97
109
|
card.md_name || "无"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-w-ygo",
|
|
3
3
|
"description": "WillBot: YuGiOh function",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"plugin"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"koishi": "^4.18.
|
|
18
|
+
"koishi": "^4.18.10"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@satorijs/element": "^3.1.8"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "yarn
|
|
25
|
-
"bump": "yarn
|
|
26
|
-
"pub": "yarn
|
|
24
|
+
"build": "yarn run -T build w-ygo",
|
|
25
|
+
"bump": "yarn run -T bump w-ygo",
|
|
26
|
+
"pub": "yarn run -T pub w-ygo"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/readme.md
CHANGED
|
@@ -3,3 +3,6 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/koishi-plugin-w-ygo)
|
|
4
4
|
|
|
5
5
|
WillBot: YuGiOh function
|
|
6
|
+
|
|
7
|
+
卡图默认使用百鸽提供的简体中文卡图,也可以通过 `cardImageUrl` 配置含 `{id}` 占位符的 URL 模板。
|
|
8
|
+
如需使用 YGOPRODeck 的英文卡图,可以配置为 `https://images.ygoprodeck.com/images/cards/{id}.jpg`。
|