koishi-plugin-aka-ai-generator 0.3.7 → 0.3.9

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.d.ts CHANGED
@@ -53,7 +53,7 @@ export interface Config {
53
53
  export interface RechargeRecord {
54
54
  id: string;
55
55
  timestamp: string;
56
- type: 'single' | 'batch';
56
+ type: 'single' | 'batch' | 'all';
57
57
  operator: {
58
58
  userId: string;
59
59
  userName: string;
package/lib/index.js CHANGED
@@ -748,6 +748,7 @@ var COMMANDS = {
748
748
  PIXELATE: "变像素",
749
749
  QUERY_QUOTA: "图像额度",
750
750
  RECHARGE: "图像充值",
751
+ RECHARGE_ALL: "活动充值",
751
752
  RECHARGE_HISTORY: "图像充值记录",
752
753
  FUNCTION_LIST: "图像功能",
753
754
  IMAGE_COMMANDS: "图像指令"
@@ -979,6 +980,7 @@ function apply(ctx, config) {
979
980
  // 管理员指令
980
981
  adminCommands: [
981
982
  { name: COMMANDS.RECHARGE, description: "为用户充值次数(仅管理员)" },
983
+ { name: COMMANDS.RECHARGE_ALL, description: "为所有用户充值次数(活动派发,仅管理员)" },
982
984
  { name: COMMANDS.RECHARGE_HISTORY, description: "查看充值历史记录(仅管理员)" }
983
985
  ]
984
986
  };
@@ -1622,78 +1624,11 @@ Prompt: ${prompt}`);
1622
1624
  return error.message === "命令执行超时" ? "图片合成超时,请重试" : `图片合成失败:${error.message}`;
1623
1625
  });
1624
1626
  });
1625
- ctx.command(`${COMMANDS.RECHARGE} [content:text]`, "为用户充值次数(仅管理员)").option("all", "-all 对所有使用过插件的用户充值").action(async ({ session, options }, content) => {
1627
+ ctx.command(`${COMMANDS.RECHARGE} [content:text]`, "为用户充值次数(仅管理员)").action(async ({ session }, content) => {
1626
1628
  if (!session?.userId) return "会话无效";
1627
1629
  if (!isAdmin(session.userId)) {
1628
1630
  return "权限不足,仅管理员可操作";
1629
1631
  }
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
- }
1697
1632
  const inputContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
1698
1633
  if (!inputContent) return "输入超时或无效";
1699
1634
  const elements = import_koishi.h.parse(inputContent);
@@ -1701,7 +1636,7 @@ Prompt: ${prompt}`);
1701
1636
  const textElements = import_koishi.h.select(elements, "text");
1702
1637
  const text = textElements.map((el) => el.attrs.content).join(" ").trim();
1703
1638
  if (atElements.length === 0) {
1704
- return "未找到@用户,请使用@用户的方式,或使用 -all 参数进行全员充值";
1639
+ return "未找到@用户,请使用@用户的方式";
1705
1640
  }
1706
1641
  const parts = text.split(/\s+/).filter((p) => p);
1707
1642
  if (parts.length === 0) {
@@ -1782,6 +1717,77 @@ Prompt: ${prompt}`);
1782
1717
  return "充值失败,请稍后重试";
1783
1718
  }
1784
1719
  });
1720
+ ctx.command(`${COMMANDS.RECHARGE_ALL} [content:text]`, "为所有用户充值次数(活动派发,仅管理员)").action(async ({ session }, content) => {
1721
+ if (!session?.userId) return "会话无效";
1722
+ if (!isAdmin(session.userId)) {
1723
+ return "权限不足,仅管理员可操作";
1724
+ }
1725
+ const inputContent = content || await getPromptInput(session, "请输入活动充值信息,格式:\n充值次数 [备注]\n例如:20 或 20 春节活动奖励");
1726
+ if (!inputContent) return "输入超时或无效";
1727
+ const elements = import_koishi.h.parse(inputContent);
1728
+ const textElements = import_koishi.h.select(elements, "text");
1729
+ const text = textElements.map((el) => el.attrs.content).join(" ").trim();
1730
+ const parts = text.split(/\s+/).filter((p) => p);
1731
+ if (parts.length === 0) {
1732
+ return "请输入充值次数,例如:图像活动充值 20 或 图像活动充值 20 活动名称";
1733
+ }
1734
+ const amount = parseInt(parts[0]);
1735
+ const note = parts.slice(1).join(" ") || "活动充值";
1736
+ if (!amount || amount <= 0) {
1737
+ return "充值次数必须大于0";
1738
+ }
1739
+ try {
1740
+ const usersData = await loadUsersData();
1741
+ const rechargeHistory = await loadRechargeHistory();
1742
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1743
+ const recordId = `recharge_all_${now.replace(/[-:T.]/g, "").slice(0, 14)}_${Math.random().toString(36).substr(2, 3)}`;
1744
+ const allUserIds = Object.keys(usersData).filter((userId) => userId && usersData[userId]);
1745
+ if (allUserIds.length === 0) {
1746
+ return "当前没有使用过插件的用户,无法进行活动充值";
1747
+ }
1748
+ const targets = [];
1749
+ for (const userId of allUserIds) {
1750
+ if (!userId) continue;
1751
+ const userData = usersData[userId];
1752
+ const userName = userData.userName || userId;
1753
+ const beforeBalance = userData.remainingPurchasedCount;
1754
+ userData.purchasedCount += amount;
1755
+ userData.remainingPurchasedCount += amount;
1756
+ targets.push({
1757
+ userId,
1758
+ userName,
1759
+ amount,
1760
+ beforeBalance,
1761
+ afterBalance: userData.remainingPurchasedCount
1762
+ });
1763
+ }
1764
+ await saveUsersData(usersData);
1765
+ const record = {
1766
+ id: recordId,
1767
+ timestamp: now,
1768
+ type: "all",
1769
+ operator: {
1770
+ userId: session.userId,
1771
+ userName: session.username || session.userId
1772
+ },
1773
+ targets,
1774
+ totalAmount: amount * allUserIds.length,
1775
+ note: note || "活动充值",
1776
+ metadata: { all: true }
1777
+ };
1778
+ rechargeHistory.records.push(record);
1779
+ await saveRechargeHistory(rechargeHistory);
1780
+ return `✅ 活动充值成功
1781
+ 目标用户数:${allUserIds.length}人
1782
+ 充值次数:${amount}次/人
1783
+ 总充值:${record.totalAmount}次
1784
+ 操作员:${record.operator.userName}
1785
+ 备注:${record.note}`;
1786
+ } catch (error) {
1787
+ logger.error("活动充值操作失败", error);
1788
+ return "活动充值失败,请稍后重试";
1789
+ }
1790
+ });
1785
1791
  ctx.command(`${COMMANDS.QUERY_QUOTA} [target:text]`, "查询用户额度信息").action(async ({ session }, target) => {
1786
1792
  if (!session?.userId) return "会话无效";
1787
1793
  const userIsAdmin = isAdmin(session.userId);
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.7",
4
+ "version": "0.3.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [