koishi-plugin-aka-ai-generator 0.3.8 → 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,102 +1624,19 @@ 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
- 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);
1632
+ const inputContent = content || await getPromptInput(session, "请输入充值信息,格式:\n@用户1 @用户2 充值次数 [备注]");
1633
+ if (!inputContent) return "输入超时或无效";
1634
+ const elements = import_koishi.h.parse(inputContent);
1716
1635
  const atElements = import_koishi.h.select(elements, "at");
1717
1636
  const textElements = import_koishi.h.select(elements, "text");
1718
1637
  const text = textElements.map((el) => el.attrs.content).join(" ").trim();
1719
1638
  if (atElements.length === 0) {
1720
- return "未找到@用户,请使用@用户的方式,或使用 -all 参数进行全员充值";
1639
+ return "未找到@用户,请使用@用户的方式";
1721
1640
  }
1722
1641
  const parts = text.split(/\s+/).filter((p) => p);
1723
1642
  if (parts.length === 0) {
@@ -1798,6 +1717,77 @@ Prompt: ${prompt}`);
1798
1717
  return "充值失败,请稍后重试";
1799
1718
  }
1800
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
+ });
1801
1791
  ctx.command(`${COMMANDS.QUERY_QUOTA} [target:text]`, "查询用户额度信息").action(async ({ session }, target) => {
1802
1792
  if (!session?.userId) return "会话无效";
1803
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.8",
4
+ "version": "0.3.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [