koishi-plugin-aka-ai-generator 0.2.18 → 0.3.1
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 +36 -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,18 @@ 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
|
+
await session.send("请输入画面描述");
|
|
1258
|
+
const msg = await session.prompt(3e4);
|
|
1259
|
+
if (!msg) return { error: "等待超时" };
|
|
1260
|
+
const elements = import_koishi.h.parse(msg);
|
|
1261
|
+
const text = import_koishi.h.select(elements, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1262
|
+
if (!text) return { error: "未检测到描述" };
|
|
1263
|
+
return { images: [], text };
|
|
1264
|
+
}
|
|
1251
1265
|
if (imgParam) {
|
|
1252
1266
|
if (typeof imgParam === "object" && imgParam.attrs?.src) {
|
|
1253
1267
|
collectedImages.push(imgParam.attrs.src);
|
|
@@ -1266,7 +1280,7 @@ function apply(ctx, config) {
|
|
|
1266
1280
|
if (collectedImages.length > 0) {
|
|
1267
1281
|
if (mode === "single") {
|
|
1268
1282
|
if (collectedImages.length > 1) {
|
|
1269
|
-
return { error: '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1283
|
+
return { error: '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令' };
|
|
1270
1284
|
}
|
|
1271
1285
|
return { images: collectedImages };
|
|
1272
1286
|
}
|
|
@@ -1458,7 +1472,19 @@ ${infoParts.join("\n")}`;
|
|
|
1458
1472
|
}
|
|
1459
1473
|
}
|
|
1460
1474
|
}
|
|
1461
|
-
ctx.command(COMMANDS.
|
|
1475
|
+
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async ({ session, options }, prompt) => {
|
|
1476
|
+
if (!session?.userId) return "会话无效";
|
|
1477
|
+
const numImages = options?.num || config.defaultNumImages;
|
|
1478
|
+
const limitCheck = await checkDailyLimit(session.userId, numImages);
|
|
1479
|
+
if (!limitCheck.allowed) {
|
|
1480
|
+
return limitCheck.message;
|
|
1481
|
+
}
|
|
1482
|
+
const requestContext = {
|
|
1483
|
+
numImages
|
|
1484
|
+
};
|
|
1485
|
+
return processImageWithTimeout(session, prompt, "", COMMANDS.TXT_TO_IMG, requestContext, {}, "text");
|
|
1486
|
+
});
|
|
1487
|
+
ctx.command(COMMANDS.IMG_TO_IMG, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async ({ session, options }) => {
|
|
1462
1488
|
if (!session?.userId) return "会话无效";
|
|
1463
1489
|
return Promise.race([
|
|
1464
1490
|
(async () => {
|
|
@@ -1481,10 +1507,10 @@ ${infoParts.join("\n")}`;
|
|
|
1481
1507
|
const text = textElements.map((el) => el.attrs.content).join(" ").trim();
|
|
1482
1508
|
if (images.length > 0) {
|
|
1483
1509
|
if (collectedImages.length > 0) {
|
|
1484
|
-
return '本功能仅支持处理一张图片,如需合成多张图片请使用"
|
|
1510
|
+
return '本功能仅支持处理一张图片,如需合成多张图片请使用"合成图"命令';
|
|
1485
1511
|
}
|
|
1486
1512
|
if (images.length > 1) {
|
|
1487
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1513
|
+
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1488
1514
|
}
|
|
1489
1515
|
for (const img of images) {
|
|
1490
1516
|
collectedImages.push(img.attrs.src);
|
|
@@ -1509,7 +1535,7 @@ ${infoParts.join("\n")}`;
|
|
|
1509
1535
|
return "未检测到图片,请重新发送";
|
|
1510
1536
|
}
|
|
1511
1537
|
if (collectedImages.length > 1) {
|
|
1512
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"
|
|
1538
|
+
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1513
1539
|
}
|
|
1514
1540
|
if (!prompt) {
|
|
1515
1541
|
return "未检测到prompt描述,请重新发送";
|
|
@@ -1545,7 +1571,7 @@ Prompt: ${prompt}`);
|
|
|
1545
1571
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1546
1572
|
}
|
|
1547
1573
|
}
|
|
1548
|
-
await recordUserUsage(session, COMMANDS.
|
|
1574
|
+
await recordUserUsage(session, COMMANDS.IMG_TO_IMG, resultImages.length);
|
|
1549
1575
|
activeTasks.delete(userId);
|
|
1550
1576
|
} catch (error) {
|
|
1551
1577
|
activeTasks.delete(userId);
|
|
@@ -1628,7 +1654,7 @@ Prompt: ${prompt}`);
|
|
|
1628
1654
|
numImages: imageCount,
|
|
1629
1655
|
imageCount: collectedImages.length
|
|
1630
1656
|
});
|
|
1631
|
-
await session.send(
|
|
1657
|
+
await session.send(`开始合成图(${collectedImages.length}张)...
|
|
1632
1658
|
Prompt: ${prompt}`);
|
|
1633
1659
|
try {
|
|
1634
1660
|
activeTasks.set(userId, "processing");
|