koishi-plugin-wordle-game 2.2.8 → 2.3.0

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 +27 -8
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -1010,6 +1010,14 @@ async function apply(ctx, config) {
1010
1010
  await setGuessRunningStatus(channelId, false);
1011
1011
  return await sendMessage(session, `【@${username}】\n操作太快了哦~\n再试一次吧!`);
1012
1012
  }
1013
+ // 运行状态
1014
+ await setGuessRunningStatus(channelId, true);
1015
+ // 更新玩家记录表中的用户名
1016
+ await updateNameInPlayerRecord(userId, username);
1017
+ if (!gameInfo.isStarted) {
1018
+ await setGuessRunningStatus(channelId, false);
1019
+ return await sendMessage(session, `【@${username}】\n游戏还没开始呢!`);
1020
+ }
1013
1021
  if (options.random) {
1014
1022
  inputWord = gameInfo.gameMode === '汉兜' || gameInfo.gameMode === '词影' ? getRandomIdiom(idiomsList).idiom : gameInfo.gameMode === 'Numberle' ? generateNumberString(gameInfo.guessWordLength) : gameInfo.gameMode === 'Math' ? getRandomFromStringList(equations[gameInfo.guessWordLength]) : getRandomWordTranslation('ALL', gameInfo.guessWordLength).word;
1015
1023
  }
@@ -1022,14 +1030,6 @@ async function apply(ctx, config) {
1022
1030
  return await sendMessage(session, `【${username}】\n猜测操作已取消!`);
1023
1031
  inputWord = userInput.trim();
1024
1032
  }
1025
- // 运行状态
1026
- await setGuessRunningStatus(channelId, true);
1027
- // 更新玩家记录表中的用户名
1028
- await updateNameInPlayerRecord(userId, username);
1029
- if (!gameInfo.isStarted) {
1030
- await setGuessRunningStatus(channelId, false);
1031
- return await sendMessage(session, `【@${username}】\n游戏还没开始呢!`);
1032
- }
1033
1033
  // 作答时间限制
1034
1034
  const timeDifferenceInSeconds = (timestamp - gameInfo.timestamp) / 1000; // 将时间戳转换为秒
1035
1035
  if (config.enableWordGuessTimeLimit) {
@@ -1433,6 +1433,7 @@ ${settlementResult}
1433
1433
  // 更新玩家记录表中的用户名
1434
1434
  await updateNameInPlayerRecord(userId, username);
1435
1435
  if (targetUser) {
1436
+ targetUser = await replaceAtTags(session, targetUser);
1436
1437
  const userIdRegex = /<at id="([^"]+)"(?: name="([^"]+)")?\/>/;
1437
1438
  const match = targetUser.match(userIdRegex);
1438
1439
  userId = match?.[1] ?? userId;
@@ -3028,6 +3029,24 @@ ${content}
3028
3029
  }
3029
3030
  }
3030
3031
  // hs*
3032
+ async function replaceAtTags(session, content) {
3033
+ // 正则表达式用于匹配 at 标签
3034
+ const atRegex = /<at id="(\d+)"(?: name="([^"]*)")?\/>/g;
3035
+ // 匹配所有 at 标签
3036
+ let match;
3037
+ while ((match = atRegex.exec(content)) !== null) {
3038
+ const userId = match[1];
3039
+ const name = match[2];
3040
+ // 如果 name 不存在,根据 userId 获取相应的 name
3041
+ if (!name) {
3042
+ const guildMember = await session.bot.getGuildMember(session.guildId, userId);
3043
+ // 替换原始的 at 标签
3044
+ const newAtTag = `<at id="${userId}" name="${guildMember.name}"/>`;
3045
+ content = content.replace(match[0], newAtTag);
3046
+ }
3047
+ }
3048
+ return content;
3049
+ }
3031
3050
  function checkStrokesData(inputWord) {
3032
3051
  for (const char of inputWord) {
3033
3052
  if (!strokesData[char]) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordle-game",
3
3
  "description": "欢迎来到 [Wordle](https://www.nytimes.com/games/wordle/index.html) | [汉兜](https://handle.antfu.me/) | [词影](https://cy.surprising.studio/) |... 猜单词|猜成语|猜数字|猜数学方程式|... 的小游戏,包含多种词库、多种主题、多种游戏设置和排行榜系统。",
4
- "version": "2.2.8",
4
+ "version": "2.3.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -61,7 +61,7 @@
61
61
  "猜"
62
62
  ],
63
63
  "peerDependencies": {
64
- "koishi": "^4.17.2"
64
+ "koishi": "^4.17.3"
65
65
  },
66
66
  "devDependencies": {
67
67
  "koishi-plugin-markdown-to-image-service": "^1.1.3",