koishi-plugin-cchess 0.0.6 → 0.0.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 CHANGED
@@ -899,6 +899,7 @@ function apply(ctx, config) {
899
899
  let { channelId, userId, username } = session;
900
900
  await updateNameInPlayerRecord(userId, username);
901
901
  if (targetUser) {
902
+ targetUser = await replaceAtTags(session, targetUser);
902
903
  const userIdRegex = /<at id="([^"]+)"(?: name="([^"]+)")?\/>/;
903
904
  const match = targetUser.match(userIdRegex);
904
905
  userId = match?.[1] ?? userId;
@@ -922,6 +923,24 @@ function apply(ctx, config) {
922
923
  `);
923
924
  });
924
925
  // hs*
926
+ async function replaceAtTags(session, content) {
927
+ // 正则表达式用于匹配 at 标签
928
+ const atRegex = /<at id="(\d+)"(?: name="([^"]*)")?\/>/g;
929
+ // 匹配所有 at 标签
930
+ let match;
931
+ while ((match = atRegex.exec(content)) !== null) {
932
+ const userId = match[1];
933
+ const name = match[2];
934
+ // 如果 name 不存在,根据 userId 获取相应的 name
935
+ if (!name) {
936
+ const guildMember = await session.bot.getGuildMember(session.guildId, userId);
937
+ // 替换原始的 at 标签
938
+ const newAtTag = `<at id="${userId}" name="${guildMember.name}"/>`;
939
+ content = content.replace(match[0], newAtTag);
940
+ }
941
+ }
942
+ return content;
943
+ }
925
944
  async function updatePlayerRecords(channelId, winSide, loseSide) {
926
945
  const winnerPlayerRecords = await ctx.database.get('cchess_gaming_player_records', {
927
946
  channelId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cchess",
3
3
  "description": "欢迎来到中国象棋游戏,支持人人/人机对战、纵线/坐标操作方式、编辑棋盘、导入/导出FEN等功能,提供 40+ 棋盘/棋子皮肤及排行榜系统。🎪",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -45,7 +45,7 @@
45
45
  "对战"
46
46
  ],
47
47
  "peerDependencies": {
48
- "koishi": "^4.17.2"
48
+ "koishi": "^4.17.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "koishi-plugin-markdown-to-image-service": "^1.1.6",
package/readme.md CHANGED
@@ -14,8 +14,7 @@
14
14
 
15
15
  - 建议自行添加别名,如 `cc` 等更方便的指令。
16
16
  - 请安装并启用所需服务,`canvas` 服务可使用 `puppeteer` 提供。
17
- -
18
- 支持使用中国象棋纵线(炮二平五/炮8平5)和字母坐标(a0a1)进行移动。[了解详情 - 中国象棋着法表示](https://www.xqbase.com/protocol/cchess_move.htm)
17
+ - 支持使用中国象棋纵线(炮二平五/炮8平5)和字母坐标(a0a1)进行移动。[了解详情 - 中国象棋着法表示](https://www.xqbase.com/protocol/cchess_move.htm)
19
18
 
20
19
  ## ⚙️ 配置项
21
20