koishi-plugin-aka-ai-generator 0.3.6 → 0.3.8

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.
Files changed (2) hide show
  1. package/lib/index.js +88 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1622,19 +1622,102 @@ 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
- const inputContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
1631
- if (!inputContent) return "输入超时或无效";
1632
- const elements = import_koishi.h.parse(inputContent);
1630
+ let useAll = options?.all;
1631
+ let inputContent = content;
1632
+ if (!useAll && inputContent) {
1633
+ const contentStr = typeof inputContent === "string" ? inputContent : inputContent ? import_koishi.h.select(import_koishi.h.parse(inputContent), "text").map((e) => e.attrs.content).join(" ") : "";
1634
+ if (contentStr && /-all\b/i.test(contentStr)) {
1635
+ useAll = true;
1636
+ inputContent = contentStr.replace(/-all\s*/gi, "").trim();
1637
+ }
1638
+ }
1639
+ if (useAll) {
1640
+ if (!inputContent || typeof inputContent === "string" && !inputContent.trim()) {
1641
+ inputContent = await getPromptInput(session, "请输入充值次数 [备注],例如:20 或 20 活动奖励");
1642
+ }
1643
+ if (!inputContent) return "输入超时或无效";
1644
+ let text2 = "";
1645
+ if (typeof inputContent === "string") {
1646
+ text2 = inputContent.trim();
1647
+ } else {
1648
+ const elements2 = import_koishi.h.parse(inputContent);
1649
+ const textElements2 = import_koishi.h.select(elements2, "text");
1650
+ text2 = textElements2.map((el) => el.attrs.content).join(" ").trim();
1651
+ }
1652
+ const parts2 = text2.split(/\s+/).filter((p) => p);
1653
+ if (parts2.length === 0) {
1654
+ return "请输入充值次数,例如:图像充值 -all 20";
1655
+ }
1656
+ const amount2 = parseInt(parts2[0]);
1657
+ const note2 = parts2.slice(1).join(" ") || "全员充值";
1658
+ if (!amount2 || amount2 <= 0) {
1659
+ return "充值次数必须大于0";
1660
+ }
1661
+ try {
1662
+ const usersData = await loadUsersData();
1663
+ const rechargeHistory = await loadRechargeHistory();
1664
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1665
+ const recordId = `recharge_${now.replace(/[-:T.]/g, "").slice(0, 14)}_${Math.random().toString(36).substr(2, 3)}`;
1666
+ const targets = [];
1667
+ const allUserIds = Object.keys(usersData);
1668
+ if (allUserIds.length === 0) {
1669
+ return "当前没有使用过插件的用户";
1670
+ }
1671
+ for (const userId of allUserIds) {
1672
+ if (!userId) continue;
1673
+ const userData = usersData[userId];
1674
+ const userName = userData.userName || userId;
1675
+ const beforeBalance = userData.remainingPurchasedCount;
1676
+ userData.purchasedCount += amount2;
1677
+ userData.remainingPurchasedCount += amount2;
1678
+ targets.push({
1679
+ userId,
1680
+ userName,
1681
+ amount: amount2,
1682
+ beforeBalance,
1683
+ afterBalance: userData.remainingPurchasedCount
1684
+ });
1685
+ }
1686
+ await saveUsersData(usersData);
1687
+ const record = {
1688
+ id: recordId,
1689
+ timestamp: now,
1690
+ type: "batch",
1691
+ operator: {
1692
+ userId: session.userId,
1693
+ userName: session.username || session.userId
1694
+ },
1695
+ targets,
1696
+ totalAmount: amount2 * allUserIds.length,
1697
+ note: note2 || "全员充值",
1698
+ metadata: { all: true }
1699
+ };
1700
+ rechargeHistory.records.push(record);
1701
+ await saveRechargeHistory(rechargeHistory);
1702
+ return `✅ 全员充值成功
1703
+ 目标用户数:${allUserIds.length}人
1704
+ 充值次数:${amount2}次/人
1705
+ 总充值:${record.totalAmount}次
1706
+ 操作员:${record.operator.userName}
1707
+ 备注:${record.note}`;
1708
+ } catch (error) {
1709
+ logger.error("全员充值操作失败", error);
1710
+ return "充值失败,请稍后重试";
1711
+ }
1712
+ }
1713
+ const rechargeContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
1714
+ if (!rechargeContent) return "输入超时或无效";
1715
+ const elements = import_koishi.h.parse(rechargeContent);
1633
1716
  const atElements = import_koishi.h.select(elements, "at");
1634
1717
  const textElements = import_koishi.h.select(elements, "text");
1635
1718
  const text = textElements.map((el) => el.attrs.content).join(" ").trim();
1636
1719
  if (atElements.length === 0) {
1637
- return "未找到@用户,请使用@用户的方式";
1720
+ return "未找到@用户,请使用@用户的方式,或使用 -all 参数进行全员充值";
1638
1721
  }
1639
1722
  const parts = text.split(/\s+/).filter((p) => p);
1640
1723
  if (parts.length === 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-aka-ai-generator",
3
3
  "description": "自用AI生成插件(GPTGod & Yunwu)",
4
- "version": "0.3.6",
4
+ "version": "0.3.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [