mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-15 12:15:05 +00:00
refactor(loldle): import champions.json directly, drop ESM wrapper
Node 24 + wrangler 4.x both accept `import ... with { type: "json" }`,
so the generated champions-data.js wrapper is no longer needed.
Drop scripts/build-loldle-data.js and the build:loldle-data npm script.
Scraper writes champions.json only.
This commit is contained in:
1 parent
470130195e
commit
b794c25a45
7 files changed
+13
-1916
No files matched your search
@@ -47,6 +47,4 @@ jobs:
|
||||
`attackType`, `region`, `lane`, `releaseDate`).
|
||||
|
||||
Review the diff, merge, then run `npm run deploy` to ship.
|
||||
add-paths: |
|
||||
src/modules/loldle/champions.json
|
||||
src/modules/loldle/champions-data.js
|
||||
add-paths: src/modules/loldle/champions.json
|
||||
+1
-2
@@ -9,8 +9,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "wrangler dev",
|
||||
"build": "npm run build:loldle-data && npm run build:wordle-data",
|
||||
"build:loldle-data": "node scripts/build-loldle-data.js",
|
||||
"build": "npm run build:wordle-data",
|
||||
"build:wordle-data": "node scripts/build-wordle-data.js",
|
||||
"scrape:loldle-data": "node scripts/scrape-loldle-data.js",
|
||||
"deploy": "npm run build && wrangler deploy && npm run db:migrate && npm run register",
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @file build-loldle-data — wraps src/modules/loldle/champions.json
|
||||
* as an ES module export to sidestep Node/esbuild disagreement on
|
||||
* JSON import attributes (Node 24 requires `with { type: "json" }`,
|
||||
* wrangler's bundled esbuild doesn't parse it yet).
|
||||
*
|
||||
* Run after any update to champions.json.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const src = resolve(root, "src/modules/loldle/champions.json");
|
||||
const dst = resolve(root, "src/modules/loldle/champions-data.js");
|
||||
|
||||
const json = readFileSync(src, "utf8").trimEnd();
|
||||
const out = [
|
||||
"// Auto-generated from champions.json — do NOT edit by hand.",
|
||||
"// Regenerate with: node scripts/build-loldle-data.js",
|
||||
`export default ${json};`,
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
writeFileSync(dst, out);
|
||||
console.log(`wrote ${dst}`);
|
||||
@@ -8,8 +8,8 @@
|
||||
* at `<script src="js/index.<hash>.js">`, one record per champion with the
|
||||
* exact shape the bot needs. No CryptoJS decoding, no ddragon merge.
|
||||
*
|
||||
* Writes both champions.json (authoring format) and champions-data.js (ESM
|
||||
* wrapper consumed by the bot).
|
||||
* Writes src/modules/loldle/champions.json. The bot imports this JSON
|
||||
* directly via `with { type: "json" }` (Node 24 + wrangler 4.x).
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/scrape-loldle-data.js
|
||||
@@ -94,21 +94,10 @@ async function scrapeLoldle() {
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const jsonPath = resolve(root, "src/modules/loldle/champions.json");
|
||||
const esmPath = resolve(root, "src/modules/loldle/champions-data.js");
|
||||
|
||||
console.log("scraping loldle.net…");
|
||||
const records = await scrapeLoldle();
|
||||
console.log(` parsed ${records.length} champions`);
|
||||
|
||||
const json = JSON.stringify(records, null, 4);
|
||||
writeFileSync(jsonPath, `${json}\n`);
|
||||
writeFileSync(jsonPath, `${JSON.stringify(records, null, 4)}\n`);
|
||||
console.log(`wrote ${jsonPath}`);
|
||||
|
||||
const esm = [
|
||||
"// Auto-generated from champions.json — do NOT edit by hand.",
|
||||
"// Regenerate with: node scripts/scrape-loldle-data.js",
|
||||
`export default ${json};`,
|
||||
"",
|
||||
].join("\n");
|
||||
writeFileSync(esmPath, esm);
|
||||
console.log(`wrote ${esmPath}`);
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
Classic-mode League of Legends champion guessing game — ported from
|
||||
[`tiennm99/loldle`](https://github.com/tiennm99/loldle) (`lib/classic-mode.js`).
|
||||
Champion data is synced from
|
||||
[`tiennm99/loldle-data`](https://github.com/tiennm99/loldle-data) via a
|
||||
GitHub Actions workflow that regenerates `champions-data.js`.
|
||||
Champion data is scraped weekly from [loldle.net](https://loldle.net/classic)'s
|
||||
JS bundle into `champions.json` via `.github/workflows/scrape-loldle-data.yml`
|
||||
(runs `node scripts/scrape-loldle-data.js`).
|
||||
|
||||
## Commands
|
||||
|
||||
@@ -22,7 +22,7 @@ immediately rolls into a fresh round — no manual "new round" command needed.
|
||||
## Architecture
|
||||
|
||||
- `compare.js` — pure attribute comparison across 7 classic-mode attributes
|
||||
(gender, genre, range, resource, region, lane, year). Returns `correct`,
|
||||
(gender, species, range, resource, region, lane, year). Returns `correct`,
|
||||
`partial`, or `wrong` per attribute, plus a `direction` hint for year.
|
||||
- `lookup.js` — normalizes user input and resolves it to a champion record.
|
||||
- `daily.js` — `pickRandom` / `pickDaily` (djb2-hashed date seed for future
|
||||
@@ -33,8 +33,9 @@ immediately rolls into a fresh round — no manual "new round" command needed.
|
||||
streak tracking.
|
||||
- `handlers.js` — wires subject resolution (user id in DMs, chat id in groups)
|
||||
to the pure functions above.
|
||||
- `champions-data.js` — auto-generated ES-module wrapper over `champions.json`
|
||||
(do not edit by hand; regenerate with `node scripts/build-loldle-data.js`).
|
||||
- `champions.json` — auto-generated from loldle.net (do not edit by hand;
|
||||
regenerate with `npm run scrape:loldle-data`). Imported directly via
|
||||
`with { type: "json" }`.
|
||||
|
||||
Subject resolution: private chats track per-user games; groups track per-chat
|
||||
shared games (everyone plays the same round).
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { escapeHtml } from "../../util/escape-html.js";
|
||||
import championsData from "./champions-data.js";
|
||||
import championsData from "./champions.json" with { type: "json" };
|
||||
import { compareChampions } from "./compare.js";
|
||||
import { pickRandom } from "./daily.js";
|
||||
import { attemptFlavor, formatDuration } from "./flavor.js";
|
||||
|
||||
Reference in new issue
Block a user