koishi-plugin-aka-ai-generator 0.3.5 → 0.3.7
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 +103 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1249,12 +1249,22 @@ function apply(ctx, config) {
|
|
|
1249
1249
|
return { images: [], text: imgParam.trim() };
|
|
1250
1250
|
}
|
|
1251
1251
|
await session.send("请输入画面描述");
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1252
|
+
while (true) {
|
|
1253
|
+
const msg = await session.prompt(3e4);
|
|
1254
|
+
if (!msg) return { error: "等待超时" };
|
|
1255
|
+
const elements = import_koishi.h.parse(msg);
|
|
1256
|
+
const images = import_koishi.h.select(elements, "img");
|
|
1257
|
+
if (images.length > 0) {
|
|
1258
|
+
await session.send("检测到图片,请发送文字描述");
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
const text = import_koishi.h.select(elements, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1262
|
+
if (!text) {
|
|
1263
|
+
await session.send("未检测到描述,请重新发送");
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
return { images: [], text };
|
|
1267
|
+
}
|
|
1258
1268
|
}
|
|
1259
1269
|
if (imgParam) {
|
|
1260
1270
|
if (typeof imgParam === "object" && imgParam.attrs?.src) {
|
|
@@ -1367,11 +1377,25 @@ function apply(ctx, config) {
|
|
|
1367
1377
|
}
|
|
1368
1378
|
finalPrompt = finalPrompt.trim();
|
|
1369
1379
|
if (!finalPrompt) {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1380
|
+
await session.send("请发送画面描述");
|
|
1381
|
+
while (true) {
|
|
1382
|
+
const promptMsg = await session.prompt(3e4);
|
|
1383
|
+
if (!promptMsg) {
|
|
1384
|
+
return "未检测到描述,请重新发送";
|
|
1385
|
+
}
|
|
1386
|
+
const elements = import_koishi.h.parse(promptMsg);
|
|
1387
|
+
const images = import_koishi.h.select(elements, "img");
|
|
1388
|
+
if (images.length > 0) {
|
|
1389
|
+
await session.send("检测到图片,请发送文字描述");
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
const text = import_koishi.h.select(elements, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1393
|
+
if (text) {
|
|
1394
|
+
finalPrompt = text;
|
|
1395
|
+
break;
|
|
1396
|
+
}
|
|
1397
|
+
await session.send("未检测到有效文字描述,请重新发送");
|
|
1373
1398
|
}
|
|
1374
|
-
finalPrompt = promptInput.trim();
|
|
1375
1399
|
}
|
|
1376
1400
|
const providerType = requestContext?.provider || config.provider;
|
|
1377
1401
|
const providerModelId = requestContext?.modelId || (providerType === "yunwu" ? config.yunwuModelId : config.gptgodModelId);
|
|
@@ -1598,11 +1622,78 @@ Prompt: ${prompt}`);
|
|
|
1598
1622
|
return error.message === "命令执行超时" ? "图片合成超时,请重试" : `图片合成失败:${error.message}`;
|
|
1599
1623
|
});
|
|
1600
1624
|
});
|
|
1601
|
-
ctx.command(`${COMMANDS.RECHARGE} [content:text]`, "为用户充值次数(仅管理员)").action(async ({ session }, content) => {
|
|
1625
|
+
ctx.command(`${COMMANDS.RECHARGE} [content:text]`, "为用户充值次数(仅管理员)").option("all", "-all 对所有使用过插件的用户充值").action(async ({ session, options }, content) => {
|
|
1602
1626
|
if (!session?.userId) return "会话无效";
|
|
1603
1627
|
if (!isAdmin(session.userId)) {
|
|
1604
1628
|
return "权限不足,仅管理员可操作";
|
|
1605
1629
|
}
|
|
1630
|
+
if (options?.all) {
|
|
1631
|
+
const inputContent2 = content || await getPromptInput(session, "请输入充值信息,格式:\n充值次数 [备注]");
|
|
1632
|
+
if (!inputContent2) return "输入超时或无效";
|
|
1633
|
+
const elements2 = import_koishi.h.parse(inputContent2);
|
|
1634
|
+
const textElements2 = import_koishi.h.select(elements2, "text");
|
|
1635
|
+
const text2 = textElements2.map((el) => el.attrs.content).join(" ").trim();
|
|
1636
|
+
const parts2 = text2.split(/\s+/).filter((p) => p);
|
|
1637
|
+
if (parts2.length === 0) {
|
|
1638
|
+
return "请输入充值次数";
|
|
1639
|
+
}
|
|
1640
|
+
const amount2 = parseInt(parts2[0]);
|
|
1641
|
+
const note2 = parts2.slice(1).join(" ") || "全员充值";
|
|
1642
|
+
if (!amount2 || amount2 <= 0) {
|
|
1643
|
+
return "充值次数必须大于0";
|
|
1644
|
+
}
|
|
1645
|
+
try {
|
|
1646
|
+
const usersData = await loadUsersData();
|
|
1647
|
+
const rechargeHistory = await loadRechargeHistory();
|
|
1648
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1649
|
+
const recordId = `recharge_${now.replace(/[-:T.]/g, "").slice(0, 14)}_${Math.random().toString(36).substr(2, 3)}`;
|
|
1650
|
+
const targets = [];
|
|
1651
|
+
const allUserIds = Object.keys(usersData);
|
|
1652
|
+
if (allUserIds.length === 0) {
|
|
1653
|
+
return "当前没有使用过插件的用户";
|
|
1654
|
+
}
|
|
1655
|
+
for (const userId of allUserIds) {
|
|
1656
|
+
if (!userId) continue;
|
|
1657
|
+
const userData = usersData[userId];
|
|
1658
|
+
const userName = userData.userName || userId;
|
|
1659
|
+
const beforeBalance = userData.remainingPurchasedCount;
|
|
1660
|
+
userData.purchasedCount += amount2;
|
|
1661
|
+
userData.remainingPurchasedCount += amount2;
|
|
1662
|
+
targets.push({
|
|
1663
|
+
userId,
|
|
1664
|
+
userName,
|
|
1665
|
+
amount: amount2,
|
|
1666
|
+
beforeBalance,
|
|
1667
|
+
afterBalance: userData.remainingPurchasedCount
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
await saveUsersData(usersData);
|
|
1671
|
+
const record = {
|
|
1672
|
+
id: recordId,
|
|
1673
|
+
timestamp: now,
|
|
1674
|
+
type: "batch",
|
|
1675
|
+
operator: {
|
|
1676
|
+
userId: session.userId,
|
|
1677
|
+
userName: session.username || session.userId
|
|
1678
|
+
},
|
|
1679
|
+
targets,
|
|
1680
|
+
totalAmount: amount2 * allUserIds.length,
|
|
1681
|
+
note: note2 || "全员充值",
|
|
1682
|
+
metadata: { all: true }
|
|
1683
|
+
};
|
|
1684
|
+
rechargeHistory.records.push(record);
|
|
1685
|
+
await saveRechargeHistory(rechargeHistory);
|
|
1686
|
+
return `✅ 全员充值成功
|
|
1687
|
+
目标用户数:${allUserIds.length}人
|
|
1688
|
+
充值次数:${amount2}次/人
|
|
1689
|
+
总充值:${record.totalAmount}次
|
|
1690
|
+
操作员:${record.operator.userName}
|
|
1691
|
+
备注:${record.note}`;
|
|
1692
|
+
} catch (error) {
|
|
1693
|
+
logger.error("全员充值操作失败", error);
|
|
1694
|
+
return "充值失败,请稍后重试";
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1606
1697
|
const inputContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
|
|
1607
1698
|
if (!inputContent) return "输入超时或无效";
|
|
1608
1699
|
const elements = import_koishi.h.parse(inputContent);
|
|
@@ -1610,7 +1701,7 @@ Prompt: ${prompt}`);
|
|
|
1610
1701
|
const textElements = import_koishi.h.select(elements, "text");
|
|
1611
1702
|
const text = textElements.map((el) => el.attrs.content).join(" ").trim();
|
|
1612
1703
|
if (atElements.length === 0) {
|
|
1613
|
-
return "
|
|
1704
|
+
return "未找到@用户,请使用@用户的方式,或使用 -all 参数进行全员充值";
|
|
1614
1705
|
}
|
|
1615
1706
|
const parts = text.split(/\s+/).filter((p) => p);
|
|
1616
1707
|
if (parts.length === 0) {
|