koishi-plugin-wordle-game 1.2.8 → 1.3.1

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 +17 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -156,7 +156,7 @@ function apply(ctx, config) {
156
156
  id: 'unsigned',
157
157
  channelId: 'string',
158
158
  isStarted: 'boolean',
159
- remainingGuessesCount: 'unsigned',
159
+ remainingGuessesCount: 'integer',
160
160
  wordAnswerChineseDefinition: 'string',
161
161
  wordGuess: 'string',
162
162
  wordGuessHtmlCache: 'text',
@@ -571,12 +571,17 @@ function apply(ctx, config) {
571
571
  wordsList = remainingWordsList;
572
572
  }
573
573
  let longestRemainingWordList = await findLongestMatchedWords(wordsList, lowercaseInputWord, targetWord, isChallengeMode);
574
- while (isChallengeMode && wordsList.includes(targetWord) && longestRemainingWordList && longestRemainingWordList.length === 1 && longestRemainingWordList[0] !== targetWord) {
575
- longestRemainingWordList = await findLongestMatchedWords(wordsList, lowercaseInputWord, targetWord, isChallengeMode);
574
+ if (!longestRemainingWordList) {
575
+ longestRemainingWordList = [];
576
576
  }
577
- // 变态挑战模式
578
- if (isChallengeMode) {
579
- isLose = !longestRemainingWordList.includes(targetWord);
577
+ else {
578
+ while (isChallengeMode && wordsList.includes(targetWord) && longestRemainingWordList && longestRemainingWordList.length === 1 && longestRemainingWordList[0] !== targetWord) {
579
+ longestRemainingWordList = await findLongestMatchedWords(wordsList, lowercaseInputWord, targetWord, isChallengeMode);
580
+ }
581
+ // 变态挑战模式
582
+ if (isChallengeMode) {
583
+ isLose = !longestRemainingWordList.includes(targetWord);
584
+ }
580
585
  }
581
586
  let randomWord = longestRemainingWordList[Math.floor(Math.random() * longestRemainingWordList.length)];
582
587
  const foundWord = findWord(randomWord);
@@ -651,9 +656,10 @@ function apply(ctx, config) {
651
656
  const styledHtml = generateStyledHtml(gameInfo.guessWordLength + 1);
652
657
  // 图
653
658
  const imageBuffer = await generateImage(styledHtml, `${gameInfo.wordGuessHtmlCache}${letterTilesHtml}\n${emptyGridHtml}`);
659
+ const remainingGuessesCount = isAbsurd ? gameInfo.remainingGuessesCount : gameInfo.remainingGuessesCount - 1;
654
660
  // 更新游戏记录
655
661
  await ctx.database.set('wordle_game_records', { channelId }, {
656
- remainingGuessesCount: gameInfo.remainingGuessesCount - 1,
662
+ remainingGuessesCount: remainingGuessesCount,
657
663
  wordGuessHtmlCache: `${gameInfo.wordGuessHtmlCache}${letterTilesHtml}\n`,
658
664
  });
659
665
  // 处理赢
@@ -1214,7 +1220,10 @@ async function findLongestMatchedWords(wordsList, lowercaseInputWord, targetWord
1214
1220
  const maxLength = Math.max(...results.map(result => result.matchedWords.length));
1215
1221
  let longestMatchedWords = results.filter(result => result.matchedWords.length === maxLength).map(result => result.matchedWords);
1216
1222
  if (isChallengeMode && wordsList.includes(targetWord)) {
1217
- longestMatchedWords = longestMatchedWords.filter(words => words.includes(targetWord));
1223
+ const filteredWords = longestMatchedWords.filter(words => words.includes(targetWord));
1224
+ if (filteredWords.length > 0) {
1225
+ longestMatchedWords = filteredWords;
1226
+ }
1218
1227
  }
1219
1228
  const randomIndex = Math.floor(Math.random() * longestMatchedWords.length);
1220
1229
  return longestMatchedWords[randomIndex];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordle-game",
3
3
  "description": "欢迎来到 Wordle 猜单词小游戏,包含多种模式、多种词库、多种游戏设置和排行榜系统。",
4
- "version": "1.2.8",
4
+ "version": "1.3.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [