koishi-plugin-hupohuhu-tupian 1.0.1 → 1.0.6
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/index.d.ts +0 -1
- package/lib/index.js +60 -11
- package/package.json +21 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -29,19 +29,68 @@ var import_koishi = require("koishi");
|
|
|
29
29
|
var name = "hupohuhu-tupian";
|
|
30
30
|
var Config = import_koishi.Schema.object({
|
|
31
31
|
endpoint: import_koishi.Schema.string().default(""),
|
|
32
|
-
kohaku: import_koishi.Schema.string().role("secret").default("")
|
|
33
|
-
maxBatchSize: import_koishi.Schema.number().default(4)
|
|
32
|
+
kohaku: import_koishi.Schema.string().role("secret").default("")
|
|
34
33
|
});
|
|
35
34
|
function apply(ctx, config) {
|
|
36
|
-
ctx.command("
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
ctx.command("hupo <prompt>").option("negative", "-n <val:string>").option("negative", "-N <val:string>").option("width", "-b <val:number>").option("width", "-B <val:number>").option("height", "-a <val:number>").option("height", "-A <val:number>").option("steps", "-i <val:number>").option("steps", "-I <val:number>").option("scale", "-f <val:number>").option("scale", "-F <val:number>").option("seed", "-s <val:number>").option("seed", "-S <val:number>").option("enhance", "-e").option("enhance", "-E").option("batch", "-x <val:number>").option("batch", "-X <val:number>").action(async ({ session, options }, prompt) => {
|
|
36
|
+
const cleanPrompt = prompt ? prompt.replace(/^["'“](.*)["'”]$/, "$1") : "";
|
|
37
|
+
if (!cleanPrompt) return "❌ 没词生个鬼,爬";
|
|
38
|
+
const check8 = /* @__PURE__ */ __name((val, name2) => {
|
|
39
|
+
if (val && val % 8 !== 0) {
|
|
40
|
+
const cut = Math.floor(val / 8) * 8;
|
|
41
|
+
throw new Error(`❌ ${name2}不是8的倍. 帮你一刀砍成 ${cut} 了。重新提交吧。`);
|
|
42
|
+
}
|
|
43
|
+
return val;
|
|
44
|
+
}, "check8");
|
|
45
|
+
try {
|
|
46
|
+
const finalPayload = {
|
|
47
|
+
prompt: cleanPrompt,
|
|
48
|
+
// P
|
|
49
|
+
negative_prompt: options.negative || "",
|
|
50
|
+
// N
|
|
51
|
+
width: check8(options.width, "宽度") || 1024,
|
|
52
|
+
// B
|
|
53
|
+
height: check8(options.height, "高度") || 1024,
|
|
54
|
+
// A
|
|
55
|
+
steps: options.steps || 20,
|
|
56
|
+
// I
|
|
57
|
+
guidance_scale: options.scale || 9,
|
|
58
|
+
// F
|
|
59
|
+
seed: options.seed || -1,
|
|
60
|
+
// S
|
|
61
|
+
enhancePrompt: !!options.enhance || session.content.includes("琥珀私照"),
|
|
62
|
+
// E
|
|
63
|
+
batch_size: options.batch || 1,
|
|
64
|
+
// X
|
|
65
|
+
kohaku: config.kohaku
|
|
66
|
+
};
|
|
67
|
+
const data = await ctx.http.post(config.endpoint, finalPayload, {
|
|
68
|
+
responseType: "arraybuffer"
|
|
69
|
+
});
|
|
70
|
+
const res = [
|
|
71
|
+
(0, import_koishi.h)("quote", { id: session.messageId }),
|
|
72
|
+
`✨ 已经生成参数为:
|
|
73
|
+
P (提示词): ${finalPayload.prompt}
|
|
74
|
+
N (负面): ${finalPayload.negative_prompt || "无"}
|
|
75
|
+
B (宽度): ${finalPayload.width}
|
|
76
|
+
A (高度): ${finalPayload.height}
|
|
77
|
+
I (步数): ${finalPayload.steps}
|
|
78
|
+
F (系数): ${finalPayload.guidance_scale}
|
|
79
|
+
S (种子): ${finalPayload.seed}
|
|
80
|
+
E (增强): ${finalPayload.enhancePrompt ? "ON" : "OFF"}
|
|
81
|
+
的图片【${finalPayload.batch_size}】张`
|
|
82
|
+
];
|
|
83
|
+
const view = new Uint8Array(data);
|
|
84
|
+
if (view[0] === 137) {
|
|
85
|
+
res.push(import_koishi.h.image(data, "image/png"));
|
|
86
|
+
return res;
|
|
87
|
+
}
|
|
88
|
+
const { images } = JSON.parse(Buffer.from(data).toString());
|
|
89
|
+
images.forEach((img) => res.push(import_koishi.h.image(img.base64)));
|
|
90
|
+
return res;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return e.message;
|
|
93
|
+
}
|
|
45
94
|
});
|
|
46
95
|
}
|
|
47
96
|
__name(apply, "apply");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-hupohuhu-tupian",
|
|
3
3
|
"description": "kon!This is a customed image generate frontend",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -11,12 +11,30 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"scripts": {},
|
|
13
13
|
"keywords": [
|
|
14
|
-
"
|
|
14
|
+
"example",
|
|
15
15
|
"koishi",
|
|
16
16
|
"plugin"
|
|
17
17
|
],
|
|
18
|
+
"private": false,
|
|
18
19
|
"devDependencies": {},
|
|
19
20
|
"peerDependencies": {
|
|
20
|
-
"koishi": "^4.
|
|
21
|
+
"koishi": "^4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"koishi": {
|
|
24
|
+
"description": {
|
|
25
|
+
"en": "this is a customed image generator ",
|
|
26
|
+
"zh": "这是一个高度定制化的生图前端"
|
|
27
|
+
},
|
|
28
|
+
"service": {
|
|
29
|
+
"required": [
|
|
30
|
+
"database"
|
|
31
|
+
],
|
|
32
|
+
"optional": [
|
|
33
|
+
"assets"
|
|
34
|
+
],
|
|
35
|
+
"implements": [
|
|
36
|
+
"dialogue"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
21
39
|
}
|
|
22
40
|
}
|