koishi-plugin-ggcevo-game 1.1.0 → 1.1.2

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
@@ -118,6 +118,8 @@ export interface PKRecord {
118
118
  wins: number;
119
119
  todayCount: number;
120
120
  lastPK: Date;
121
+ enable: boolean;
122
+ lastToggle: Date;
121
123
  }
122
124
  interface PKLog {
123
125
  id: number;
package/lib/index.js CHANGED
@@ -175,7 +175,15 @@ function apply(ctx, config) {
175
175
  total: "unsigned",
176
176
  wins: "unsigned",
177
177
  todayCount: "unsigned",
178
- lastPK: "timestamp"
178
+ lastPK: "timestamp",
179
+ enable: {
180
+ // 新增字段
181
+ type: "boolean",
182
+ initial: true
183
+ // 默认开启
184
+ },
185
+ lastToggle: "timestamp"
186
+ // 新增字段
179
187
  }, {
180
188
  primary: "handle"
181
189
  });
@@ -297,7 +305,7 @@ function apply(ctx, config) {
297
305
  }
298
306
  const quantity = backpack.quantity;
299
307
  if (quantity < 1) {
300
- return "您的咕咕币不足";
308
+ return "您的咕咕币不足~";
301
309
  }
302
310
  await ctx.database.upsert("ggcevo_backpack", [{
303
311
  handle,
@@ -335,7 +343,7 @@ function apply(ctx, config) {
335
343
  return "您还没有进行过签到。";
336
344
  }
337
345
  if (backpack.quantity < 1) {
338
- return "您的咕咕币不足";
346
+ return "您的咕咕币不足~";
339
347
  }
340
348
  await ctx.database.upsert("ggcevo_backpack", [{
341
349
  handle,
@@ -368,7 +376,7 @@ function apply(ctx, config) {
368
376
  return "您还没有进行过签到。";
369
377
  }
370
378
  if (backpack.quantity < 10) {
371
- return "您的咕咕币不足";
379
+ return "您的咕咕币不足~";
372
380
  }
373
381
  await ctx.database.upsert("ggcevo_backpack", [{
374
382
  handle,
@@ -421,7 +429,7 @@ function apply(ctx, config) {
421
429
  const [itemName, itemData] = entry;
422
430
  return `${itemName} × ${userItem.quantity}:${itemData.description}`;
423
431
  });
424
- return `【你的背包】
432
+ return `【${handle}的背包】
425
433
  ${itemDetails.join("\n")}`;
426
434
  });
427
435
  ctx.command("ggcevo/签到").action(async (argv) => {
@@ -966,22 +974,22 @@ ID:${activity.id}
966
974
  let targetUsername = parsedUser.attrs.name || targetUserId;
967
975
  const [profile] = await ctx.database.get("sc2arcade_player", { userId: targetUsername });
968
976
  if (!profile) {
969
- return "他/她的 QQ 未绑定句柄。";
977
+ return "对方的 QQ 未绑定句柄。";
970
978
  }
971
979
  const { regionId, realmId, profileId } = profile;
972
980
  const handle = `${regionId}-S2-${realmId}-${profileId}`;
973
981
  const [user] = await ctx.database.get("ggcevo_rank", {
974
982
  handle
975
983
  });
976
- if (!user) return "未找到他/她的排名信息。";
977
- if (user.Blacklist) return "❌他/她已经被禁止参加本赛季胜点榜。";
984
+ if (!user) return "未找到对方的排名信息。";
985
+ if (user.Blacklist) return "❌对方已经被禁止参加本赛季胜点榜。";
978
986
  const allRanks = await ctx.database.select("ggcevo_rank").where({ Blacklist: false }).orderBy("rank", "desc").execute();
979
987
  const userRank = allRanks.findIndex(
980
988
  (u) => u.handle === handle
981
989
  ) + 1;
982
990
  const isSafe = await checkSensitiveWord(user.name);
983
991
  const displayName = isSafe ? user.name : (user.name[0] || "") + "***";
984
- return `🎮 他/她的 GGCEvo 排名信息 🎮
992
+ return `🎮 对方的 GGCEvo 排名信息 🎮
985
993
  ------------------------------
986
994
  昵称:${displayName}
987
995
  句柄:${user.handle}
@@ -1031,7 +1039,7 @@ ID:${activity.id}
1031
1039
  let targetUsername = parsedUser.attrs.name || targetUserId;
1032
1040
  const [profile] = await ctx.database.get("sc2arcade_player", { userId: targetUsername });
1033
1041
  if (!profile) {
1034
- return "他/她的 QQ 未绑定句柄。";
1042
+ return "对方的 QQ 未绑定句柄。";
1035
1043
  }
1036
1044
  const { regionId, realmId, profileId } = profile;
1037
1045
  handle = `${regionId}-S2-${realmId}-${profileId}`;
@@ -1504,6 +1512,11 @@ ${achievementList.join("\n")}`;
1504
1512
  if (!user) return '缺少参数,请输入"pk @指定对战玩家"';
1505
1513
  const [profile] = await ctx.database.get("sc2arcade_player", { userId: session.userId });
1506
1514
  if (!profile) return "您的 QQ 未绑定句柄。";
1515
+ const handle = `${profile.regionId}-S2-${profile.realmId}-${profile.profileId}`;
1516
+ const existingEntries = await ctx.database.get("ggcevo_blacklist", { handle });
1517
+ if (existingEntries.length > 0) {
1518
+ return `❌拒绝访问,您已被列入活动黑名单。`;
1519
+ }
1507
1520
  const parsedUser = import_koishi.h.parse(user)[0];
1508
1521
  if (!parsedUser || parsedUser.type !== "at") return '参数格式错误,请输入"pk @指定对战玩家"';
1509
1522
  const targetUserId = parsedUser.attrs.id;
@@ -1518,15 +1531,23 @@ ${achievementList.join("\n")}`;
1518
1531
  total: 0,
1519
1532
  wins: 0,
1520
1533
  todayCount: 0,
1521
- lastPK: /* @__PURE__ */ new Date(0)
1534
+ lastPK: /* @__PURE__ */ new Date(0),
1522
1535
  // 明确初始化 lastPK
1536
+ enable: true,
1537
+ // 新增默认值
1538
+ lastToggle: /* @__PURE__ */ new Date(0)
1539
+ // 新增默认值
1523
1540
  };
1524
1541
  let targetPK = {
1525
1542
  handle: targetHandle,
1526
1543
  total: 0,
1527
1544
  wins: 0,
1528
1545
  todayCount: 0,
1529
- lastPK: /* @__PURE__ */ new Date(0)
1546
+ lastPK: /* @__PURE__ */ new Date(0),
1547
+ enable: true,
1548
+ // 新增默认值
1549
+ lastToggle: /* @__PURE__ */ new Date(0)
1550
+ // 新增默认值
1530
1551
  };
1531
1552
  await ctx.database.withTransaction(async () => {
1532
1553
  const [dbInitiator] = await ctx.database.get("ggcevo_pk", { handle: initiatorHandle });
@@ -1534,6 +1555,12 @@ ${achievementList.join("\n")}`;
1534
1555
  const [dbTarget] = await ctx.database.get("ggcevo_pk", { handle: targetHandle });
1535
1556
  if (dbTarget) Object.assign(targetPK, dbTarget);
1536
1557
  });
1558
+ if (!initiatorPK.enable) {
1559
+ return "您已关闭PK功能,无法发起挑战";
1560
+ }
1561
+ if (!targetPK.enable) {
1562
+ return "对方已关闭PK功能,无法接受挑战";
1563
+ }
1537
1564
  const now = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1538
1565
  if (!isSameDate(convertUTCtoChinaTime(initiatorPK.lastPK), now)) {
1539
1566
  initiatorPK.todayCount = 0;
@@ -1564,6 +1591,13 @@ ${achievementList.join("\n")}`;
1564
1591
  return `该玩家今日已被挑战太多次(最多${config.maxDailyBeChallenged}次)`;
1565
1592
  }
1566
1593
  }
1594
+ const [finalInitiator, finalTarget] = await Promise.all([
1595
+ ctx.database.get("ggcevo_pk", initiatorHandle),
1596
+ ctx.database.get("ggcevo_pk", targetHandle)
1597
+ ]);
1598
+ if (!finalInitiator[0]?.enable || !finalTarget[0]?.enable) {
1599
+ return "对战状态已发生变化,请重新发起挑战";
1600
+ }
1567
1601
  const [initiatorData, targetData] = await Promise.all([
1568
1602
  ctx.database.get("ggcevo_rank", initiatorHandle),
1569
1603
  ctx.database.get("ggcevo_rank", targetHandle)
@@ -1601,7 +1635,11 @@ ${achievementList.join("\n")}`;
1601
1635
  total: initiatorPK.total + 1,
1602
1636
  wins: isWin ? initiatorPK.wins + 1 : initiatorPK.wins,
1603
1637
  todayCount: initiatorPK.todayCount + 1,
1604
- lastPK: /* @__PURE__ */ new Date()
1638
+ lastPK: /* @__PURE__ */ new Date(),
1639
+ enable: initiatorPK.enable,
1640
+ // 包含新字段
1641
+ lastToggle: initiatorPK.lastToggle
1642
+ // 包含新字段
1605
1643
  },
1606
1644
  // 应战者记录(新增部分)
1607
1645
  {
@@ -1611,8 +1649,12 @@ ${achievementList.join("\n")}`;
1611
1649
  // 应战者胜利时增加
1612
1650
  todayCount: targetPK.todayCount,
1613
1651
  // 不消耗应战者次数
1614
- lastPK: targetPK.lastPK
1652
+ lastPK: targetPK.lastPK,
1615
1653
  // 保留原有时间不更新
1654
+ enable: targetPK.enable,
1655
+ // 包含新字段
1656
+ lastToggle: targetPK.lastToggle
1657
+ // 包含新字段
1616
1658
  }
1617
1659
  ]);
1618
1660
  await ctx.database.create("ggcevo_pk_logs", {
@@ -1643,6 +1685,56 @@ ${achievementList.join("\n")}`;
1643
1685
  return "对战功能暂时不可用,请稍后重试";
1644
1686
  }
1645
1687
  });
1688
+ ctx.command("ggcevo/切换pk状态", "切换玩家对战状态").action(async ({ session }) => {
1689
+ const [profile] = await ctx.database.get("sc2arcade_player", { userId: session.userId });
1690
+ if (!profile) return "您的 QQ 未绑定句柄";
1691
+ const handle = `${profile.regionId}-S2-${profile.realmId}-${profile.profileId}`;
1692
+ const existingEntries = await ctx.database.get("ggcevo_blacklist", { handle });
1693
+ if (existingEntries.length > 0) {
1694
+ return `❌拒绝访问,您已被列入活动黑名单。`;
1695
+ }
1696
+ const [pkRecord] = await ctx.database.get("ggcevo_pk", { handle }) || [null];
1697
+ const currentState = pkRecord?.enable ?? true;
1698
+ const lastToggle = pkRecord?.lastToggle ?? /* @__PURE__ */ new Date(0);
1699
+ if (!pkRecord) {
1700
+ await ctx.database.create("ggcevo_pk", {
1701
+ handle,
1702
+ total: 0,
1703
+ wins: 0,
1704
+ todayCount: 0,
1705
+ lastPK: /* @__PURE__ */ new Date(0),
1706
+ enable: true,
1707
+ // 默认初始状态为开启
1708
+ lastToggle: /* @__PURE__ */ new Date(0)
1709
+ });
1710
+ }
1711
+ const now = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1712
+ const lastToggleTime = convertUTCtoChinaTime(lastToggle);
1713
+ const diffDays = Math.floor((now.getTime() - lastToggleTime.getTime()) / (1e3 * 3600 * 24));
1714
+ if (diffDays < 3 && lastToggleTime.getTime() !== 0) {
1715
+ const remaining = 3 - diffDays;
1716
+ return `状态切换冷却中,${remaining}天后再试(下次可切换时间:${new Date(lastToggle.getTime() + 3 * 864e5).toLocaleDateString("zh-CN")})`;
1717
+ }
1718
+ const action = currentState ? "关闭" : "开启";
1719
+ await session.send(`您当前的PK状态为【${currentState ? "开启" : "关闭"}】,确认要${action}吗?(30秒内回复“是”确认)`);
1720
+ const confirm = await session.prompt(3e4);
1721
+ if (confirm !== "是") return "已取消操作";
1722
+ await ctx.database.upsert("ggcevo_pk", [{
1723
+ handle,
1724
+ enable: !currentState,
1725
+ lastToggle: /* @__PURE__ */ new Date(),
1726
+ // 保持其他字段不变
1727
+ total: pkRecord?.total || 0,
1728
+ wins: pkRecord?.wins || 0,
1729
+ todayCount: pkRecord?.todayCount || 0,
1730
+ lastPK: pkRecord?.lastPK || /* @__PURE__ */ new Date(0)
1731
+ }], ["handle"]);
1732
+ return `PK状态已${!currentState ? "开启" : "关闭"},下次可切换时间:${new Date(Date.now() + 3 * 864e5).toLocaleDateString("zh-CN", {
1733
+ year: "numeric",
1734
+ month: "2-digit",
1735
+ day: "2-digit"
1736
+ })}`;
1737
+ });
1646
1738
  }
1647
1739
  __name(apply, "apply");
1648
1740
  function simpleDraw() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ggcevo-game",
3
3
  "description": "星际争霸2游戏大厅咕咕虫-Evo地图专属插件",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -17,7 +17,7 @@
17
17
  "peerDependencies": {
18
18
  "koishi": "^4.18.7",
19
19
  "@koishijs/plugin-proxy-agent": "^0.3.3",
20
- "koishi-plugin-sc2arcade-search": "^1.0.3"
20
+ "koishi-plugin-sc2arcade-search": "^1.1.0"
21
21
  },
22
22
  "koishi": {
23
23
  "service": {