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 +34 -26
- package/lib/utils/resource.d.ts +4 -0
- package/package.json +1 -1
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
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
14098
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15090
|
+
fs5.readFileSync(fileData.filePath, "utf-8")
|
|
15083
15091
|
);
|
|
15084
15092
|
wordsList = extractLowerCaseWords(jsonData);
|
|
15085
15093
|
} else {
|
|
15086
15094
|
const jsonData = JSON.parse(
|
|
15087
|
-
|
|
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 =
|
|
16232
|
-
const strokesData = JSON.parse(
|
|
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
|
-
|
|
16242
|
+
fs6.readFileSync(pinyinKoishiFilePath, "utf8")
|
|
16235
16243
|
);
|
|
16236
16244
|
const equations = JSON.parse(
|
|
16237
|
-
|
|
16245
|
+
fs6.readFileSync(equationsFilePath, "utf8")
|
|
16238
16246
|
);
|
|
16239
16247
|
const idiomsList = JSON.parse(idiomsData);
|
|
16240
|
-
const introductionImgBuffer =
|
|
16248
|
+
const introductionImgBuffer = fs6.readFileSync(introductionFilePath);
|
|
16241
16249
|
ctx.model.extend(
|
|
16242
16250
|
"wordle_game_records",
|
|
16243
16251
|
{
|