koishi-plugin-aka-ai-generator 0.3.6 → 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 +69 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1622,11 +1622,78 @@ Prompt: ${prompt}`);
|
|
|
1622
1622
|
return error.message === "命令执行超时" ? "图片合成超时,请重试" : `图片合成失败:${error.message}`;
|
|
1623
1623
|
});
|
|
1624
1624
|
});
|
|
1625
|
-
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) => {
|
|
1626
1626
|
if (!session?.userId) return "会话无效";
|
|
1627
1627
|
if (!isAdmin(session.userId)) {
|
|
1628
1628
|
return "权限不足,仅管理员可操作";
|
|
1629
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
|
+
}
|
|
1630
1697
|
const inputContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
|
|
1631
1698
|
if (!inputContent) return "输入超时或无效";
|
|
1632
1699
|
const elements = import_koishi.h.parse(inputContent);
|
|
@@ -1634,7 +1701,7 @@ Prompt: ${prompt}`);
|
|
|
1634
1701
|
const textElements = import_koishi.h.select(elements, "text");
|
|
1635
1702
|
const text = textElements.map((el) => el.attrs.content).join(" ").trim();
|
|
1636
1703
|
if (atElements.length === 0) {
|
|
1637
|
-
return "
|
|
1704
|
+
return "未找到@用户,请使用@用户的方式,或使用 -all 参数进行全员充值";
|
|
1638
1705
|
}
|
|
1639
1706
|
const parts = text.split(/\s+/).filter((p) => p);
|
|
1640
1707
|
if (parts.length === 0) {
|