koishi-plugin-wordle-game 4.1.2 → 4.1.3

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
@@ -37,7 +37,7 @@ __export(src_exports, {
37
37
  usage: () => usage
38
38
  });
39
39
  module.exports = __toCommonJS(src_exports);
40
- var fs5 = __toESM(require("fs"));
40
+ var fs6 = __toESM(require("fs"));
41
41
  var path3 = __toESM(require("path"));
42
42
 
43
43
  // src/config.ts
@@ -715,7 +715,7 @@ function register(g) {
715
715
  __name(register, "register");
716
716
 
717
717
  // src/commands/game.ts
718
- var fs4 = __toESM(require("fs"));
718
+ var fs5 = __toESM(require("fs"));
719
719
  var import_koishi4 = require("koishi");
720
720
 
721
721
  // src/assets/Wordle/词汇/badWordsList.json
@@ -12340,7 +12340,6 @@ async function generateLetterTilesHtmlForHandle(g, answerIdiom, userInputIdiom,
12340
12340
  __name(generateLetterTilesHtmlForHandle, "generateLetterTilesHtmlForHandle");
12341
12341
 
12342
12342
  // src/services/renderer.ts
12343
- var path = __toESM(require("path"));
12344
12343
  var import_url = require("url");
12345
12344
  var import_koishi3 = require("koishi");
12346
12345
 
@@ -13615,6 +13614,23 @@ var defaultPinyinsHtml = ` <div grid="~ cols-2 gap-3" h-min="
13615
13614
  <div class="">ün</div>
13616
13615
  </div>`;
13617
13616
 
13617
+ // src/utils/resource.ts
13618
+ var fs3 = __toESM(require("fs"));
13619
+ var path = __toESM(require("path"));
13620
+ var moduleDir = __dirname;
13621
+ var root = path.basename(moduleDir) === "lib" ? moduleDir : path.resolve(moduleDir, "..");
13622
+ var missing = ["assets", "emptyHtml.html"].filter(
13623
+ (entry) => !fs3.existsSync(path.join(root, entry))
13624
+ );
13625
+ if (missing.length > 0) {
13626
+ throw new Error(`资源根 ${root} 缺少 ${missing.join("、")}`);
13627
+ }
13628
+ var resourceRoot = root;
13629
+ function resource(...segments) {
13630
+ return path.join(resourceRoot, ...segments);
13631
+ }
13632
+ __name(resource, "resource");
13633
+
13618
13634
  // src/services/renderer.ts
13619
13635
  var HUE = 142;
13620
13636
  var PANEL_WIDTH = 611;
@@ -13623,9 +13639,7 @@ async function capture(g, html, viewport, fileOrigin = false) {
13623
13639
  try {
13624
13640
  await page.setViewport({ ...viewport, deviceScaleFactor: 1 });
13625
13641
  if (fileOrigin) {
13626
- await page.goto(
13627
- (0, import_url.pathToFileURL)(path.join(__dirname, "emptyHtml.html")).href
13628
- );
13642
+ await page.goto((0, import_url.pathToFileURL)(resource("emptyHtml.html")).href);
13629
13643
  }
13630
13644
  await page.setContent(html, { waitUntil: "load" });
13631
13645
  return await page.screenshot({
@@ -13971,7 +13985,7 @@ function getRandomFromStringList(words) {
13971
13985
  __name(getRandomFromStringList, "getRandomFromStringList");
13972
13986
 
13973
13987
  // src/utils/wordle.ts
13974
- var fs3 = __toESM(require("fs"));
13988
+ var fs4 = __toESM(require("fs"));
13975
13989
  var path2 = __toESM(require("path"));
13976
13990
  function extractLowerCaseWords(arr) {
13977
13991
  return arr.map((item) => item.word.toLowerCase());
@@ -14059,7 +14073,7 @@ function findWord(targetWord) {
14059
14073
  "ALL",
14060
14074
  targetWord.length
14061
14075
  );
14062
- const jsonData = JSON.parse(fs3.readFileSync(fileData.filePath, "utf-8"));
14076
+ const jsonData = JSON.parse(fs4.readFileSync(fileData.filePath, "utf-8"));
14063
14077
  const lowercaseTargetWord = targetWord.toLowerCase();
14064
14078
  return jsonData.find(
14065
14079
  (entry) => entry.word.toLowerCase() === lowercaseTargetWord
@@ -14072,7 +14086,7 @@ function getRandomWordTranslation(command, guessWordLength) {
14072
14086
  guessWordLength
14073
14087
  );
14074
14088
  if (command === "ALL") {
14075
- const jsonData = JSON.parse(fs3.readFileSync(fileData.filePath, "utf-8"));
14089
+ const jsonData = JSON.parse(fs4.readFileSync(fileData.filePath, "utf-8"));
14076
14090
  const randomIndex = Math.floor(Math.random() * jsonData.length);
14077
14091
  const randomWordData = jsonData[randomIndex];
14078
14092
  return {
@@ -14081,7 +14095,7 @@ function getRandomWordTranslation(command, guessWordLength) {
14081
14095
  wordCount: jsonData.length
14082
14096
  };
14083
14097
  } else {
14084
- const jsonData = JSON.parse(fs3.readFileSync(fileData.filePath, "utf-8"));
14098
+ const jsonData = JSON.parse(fs4.readFileSync(fileData.filePath, "utf-8"));
14085
14099
  const words = Object.keys(jsonData);
14086
14100
  const randomWord = words[Math.floor(Math.random() * words.length)];
14087
14101
  const translation = jsonData[randomWord]["中释"].trim();
@@ -14094,14 +14108,8 @@ function getRandomWordTranslation(command, guessWordLength) {
14094
14108
  }
14095
14109
  __name(getRandomWordTranslation, "getRandomWordTranslation");
14096
14110
  function getJsonFilePathAndWordCountByLength(command, guessWordLength) {
14097
- const folderPath = path2.join(
14098
- __dirname,
14099
- "assets",
14100
- "Wordle",
14101
- "词汇",
14102
- command
14103
- );
14104
- const files = fs3.readdirSync(folderPath);
14111
+ const folderPath = resource("assets", "Wordle", "词汇", command);
14112
+ const files = fs4.readdirSync(folderPath);
14105
14113
  for (const file of files) {
14106
14114
  const match = file.match(new RegExp(`${command}_(\\d+)_(\\d+)\\.json`));
14107
14115
  if (match && match[1] && match[2]) {
@@ -14991,7 +14999,7 @@ ${progressMessage}${processedResult}`
14991
14999
  pinyin: userInputPinyin
14992
15000
  };
14993
15001
  pinyinData.push(newItem);
14994
- fs4.writeFileSync(
15002
+ fs5.writeFileSync(
14995
15003
  g.paths.pinyinKoishi,
14996
15004
  JSON.stringify(pinyinData, null, 2),
14997
15005
  "utf8"
@@ -15079,12 +15087,12 @@ ${rule}
15079
15087
  );
15080
15088
  if (gameMode === "ALL") {
15081
15089
  const jsonData = JSON.parse(
15082
- fs4.readFileSync(fileData.filePath, "utf-8")
15090
+ fs5.readFileSync(fileData.filePath, "utf-8")
15083
15091
  );
15084
15092
  wordsList = extractLowerCaseWords(jsonData);
15085
15093
  } else {
15086
15094
  const jsonData = JSON.parse(
15087
- fs4.readFileSync(fileData.filePath, "utf-8")
15095
+ fs5.readFileSync(fileData.filePath, "utf-8")
15088
15096
  );
15089
15097
  wordsList = Object.keys(jsonData).map(
15090
15098
  (word) => word.toLowerCase()
@@ -16228,16 +16236,16 @@ async function apply(ctx, config) {
16228
16236
  await ensureFileExists(pinyinKoishiFilePath);
16229
16237
  await updateDataInTargetFile(logger, idiomsFilePath, idiomsKoishiFilePath, "idiom");
16230
16238
  await updateDataInTargetFile(logger, pinyinFilePath, pinyinKoishiFilePath, "term");
16231
- const idiomsData = fs5.readFileSync(idiomsKoishiFilePath, "utf-8");
16232
- const strokesData = JSON.parse(fs5.readFileSync(strokesFilePath, "utf-8"));
16239
+ const idiomsData = fs6.readFileSync(idiomsKoishiFilePath, "utf-8");
16240
+ const strokesData = JSON.parse(fs6.readFileSync(strokesFilePath, "utf-8"));
16233
16241
  const pinyinData = JSON.parse(
16234
- fs5.readFileSync(pinyinKoishiFilePath, "utf8")
16242
+ fs6.readFileSync(pinyinKoishiFilePath, "utf8")
16235
16243
  );
16236
16244
  const equations = JSON.parse(
16237
- fs5.readFileSync(equationsFilePath, "utf8")
16245
+ fs6.readFileSync(equationsFilePath, "utf8")
16238
16246
  );
16239
16247
  const idiomsList = JSON.parse(idiomsData);
16240
- const introductionImgBuffer = fs5.readFileSync(introductionFilePath);
16248
+ const introductionImgBuffer = fs6.readFileSync(introductionFilePath);
16241
16249
  ctx.model.extend(
16242
16250
  "wordle_game_records",
16243
16251
  {
@@ -0,0 +1,4 @@
1
+ /** 资源根。开发模式是包内 src/,生产模式是包内 lib/。 */
2
+ export declare const resourceRoot: string;
3
+ /** 取资源根下的路径。 */
4
+ export declare function resource(...segments: string[]): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordle-game",
3
3
  "description": "Koishi 插件 · 猜单词。",
4
- "version": "4.1.2",
4
+ "version": "4.1.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [