koishi-plugin-aka-ai-generator 0.2.18 → 0.3.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.
- package/lib/index.js +41 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -740,8 +740,9 @@ __name(createImageProvider, "createImageProvider");
|
|
|
740
740
|
// src/index.ts
|
|
741
741
|
var name = "aka-ai-generator";
|
|
742
742
|
var COMMANDS = {
|
|
743
|
-
|
|
744
|
-
|
|
743
|
+
IMG_TO_IMG: "图生图",
|
|
744
|
+
TXT_TO_IMG: "文生图",
|
|
745
|
+
COMPOSE_IMAGE: "合成图",
|
|
745
746
|
CHANGE_POSE: "改姿势",
|
|
746
747
|
OPTIMIZE_DESIGN: "修改设计",
|
|
747
748
|
PIXELATE: "变像素",
|
|
@@ -976,7 +977,8 @@ function apply(ctx, config) {
|
|
|
976
977
|
// 非管理员指令(包含动态风格指令)
|
|
977
978
|
userCommands: [
|
|
978
979
|
...getStyleCommands(),
|
|
979
|
-
{ name: COMMANDS.
|
|
980
|
+
{ name: COMMANDS.TXT_TO_IMG, description: "根据文字描述生成图像" },
|
|
981
|
+
{ name: COMMANDS.IMG_TO_IMG, description: "使用自定义prompt进行图像处理(图生图)" },
|
|
980
982
|
{ name: COMMANDS.COMPOSE_IMAGE, description: "合成多张图片,使用自定义prompt控制合成效果" },
|
|
981
983
|
{ name: COMMANDS.QUERY_QUOTA, description: "查询用户额度信息" }
|
|
982
984
|
],
|
|
@@ -1248,6 +1250,23 @@ function apply(ctx, config) {
|
|
|
1248
1250
|
async function getInputData(session, imgParam, mode) {
|
|
1249
1251
|
const collectedImages = [];
|
|
1250
1252
|
let collectedText = "";
|
|
1253
|
+
if (mode === "text") {
|
|
1254
|
+
if (typeof imgParam === "string" && imgParam.trim()) {
|
|
1255
|
+
return { images: [], text: imgParam.trim() };
|
|
1256
|
+
}
|
|
1257
|
+
if (session.content) {
|
|
1258
|
+
const elements2 = import_koishi.h.parse(session.content);
|
|
1259
|
+
const text2 = import_koishi.h.select(elements2, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1260
|
+
if (text2) return { images: [], text: text2 };
|
|
1261
|
+
}
|
|
1262
|
+
await session.send("请输入画面描述");
|
|
1263
|
+
const msg = await session.prompt(3e4);
|
|
1264
|
+
if (!msg) return { error: "等待超时" };
|
|
1265
|
+
const elements = import_koishi.h.parse(msg);
|
|
1266
|
+
const text = import_koishi.h.select(elements, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1267
|
+
if (!text) return { error: "未检测到描述" };
|
|
1268
|
+
return { images: [], text };
|
|
1269
|
+
}
|
|
1251
1270
|
if (imgParam) {
|
|
1252
1271
|
if (typeof imgParam === "object" && imgParam.attrs?.src) {
|
|
1253
1272
|
collectedImages.push(imgParam.attrs.src);
|
|
@@ -1266,7 +1285,7 @@ function apply(ctx, config) {
|
|
|
1266
1285
|
if (collectedImages.length > 0) {
|
|
1267
1286
|
if (mode === "single") {
|
|
1268
1287
|
if (collectedImages.length > 1) {
|
|
1269
|
-
return { error: '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1288
|
+
return { error: '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令' };
|
|
1270
1289
|
}
|
|
1271
1290
|
return { images: collectedImages };
|
|
1272
1291
|
}
|
|
@@ -1458,7 +1477,19 @@ ${infoParts.join("\n")}`;
|
|
|
1458
1477
|
}
|
|
1459
1478
|
}
|
|
1460
1479
|
}
|
|
1461
|
-
ctx.command(COMMANDS.
|
|
1480
|
+
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async ({ session, options }, prompt) => {
|
|
1481
|
+
if (!session?.userId) return "会话无效";
|
|
1482
|
+
const numImages = options?.num || config.defaultNumImages;
|
|
1483
|
+
const limitCheck = await checkDailyLimit(session.userId, numImages);
|
|
1484
|
+
if (!limitCheck.allowed) {
|
|
1485
|
+
return limitCheck.message;
|
|
1486
|
+
}
|
|
1487
|
+
const requestContext = {
|
|
1488
|
+
numImages
|
|
1489
|
+
};
|
|
1490
|
+
return processImageWithTimeout(session, prompt, "", COMMANDS.TXT_TO_IMG, requestContext, {}, "text");
|
|
1491
|
+
});
|
|
1492
|
+
ctx.command(COMMANDS.IMG_TO_IMG, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async ({ session, options }) => {
|
|
1462
1493
|
if (!session?.userId) return "会话无效";
|
|
1463
1494
|
return Promise.race([
|
|
1464
1495
|
(async () => {
|
|
@@ -1481,10 +1512,10 @@ ${infoParts.join("\n")}`;
|
|
|
1481
1512
|
const text = textElements.map((el) => el.attrs.content).join(" ").trim();
|
|
1482
1513
|
if (images.length > 0) {
|
|
1483
1514
|
if (collectedImages.length > 0) {
|
|
1484
|
-
return '本功能仅支持处理一张图片,如需合成多张图片请使用"
|
|
1515
|
+
return '本功能仅支持处理一张图片,如需合成多张图片请使用"合成图"命令';
|
|
1485
1516
|
}
|
|
1486
1517
|
if (images.length > 1) {
|
|
1487
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1518
|
+
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1488
1519
|
}
|
|
1489
1520
|
for (const img of images) {
|
|
1490
1521
|
collectedImages.push(img.attrs.src);
|
|
@@ -1509,7 +1540,7 @@ ${infoParts.join("\n")}`;
|
|
|
1509
1540
|
return "未检测到图片,请重新发送";
|
|
1510
1541
|
}
|
|
1511
1542
|
if (collectedImages.length > 1) {
|
|
1512
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1543
|
+
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1513
1544
|
}
|
|
1514
1545
|
if (!prompt) {
|
|
1515
1546
|
return "未检测到prompt描述,请重新发送";
|
|
@@ -1545,7 +1576,7 @@ Prompt: ${prompt}`);
|
|
|
1545
1576
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1546
1577
|
}
|
|
1547
1578
|
}
|
|
1548
|
-
await recordUserUsage(session, COMMANDS.
|
|
1579
|
+
await recordUserUsage(session, COMMANDS.IMG_TO_IMG, resultImages.length);
|
|
1549
1580
|
activeTasks.delete(userId);
|
|
1550
1581
|
} catch (error) {
|
|
1551
1582
|
activeTasks.delete(userId);
|
|
@@ -1628,7 +1659,7 @@ Prompt: ${prompt}`);
|
|
|
1628
1659
|
numImages: imageCount,
|
|
1629
1660
|
imageCount: collectedImages.length
|
|
1630
1661
|
});
|
|
1631
|
-
await session.send(
|
|
1662
|
+
await session.send(`开始合成图(${collectedImages.length}张)...
|
|
1632
1663
|
Prompt: ${prompt}`);
|
|
1633
1664
|
try {
|
|
1634
1665
|
activeTasks.set(userId, "processing");
|