Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions scripts/generate-secrets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 1. Ask Blizzard API credential (https://develop.battle.net/access/clients)
// 2. Fetch all secret cards
// 3. Fetch cards from hearthstonejson
// 4. Make JSON with pairs of ID and description

const path = require("path");
const got = require("got");
const inquirer = require("inquirer");
const writeJson = require("write-json-file");

const getAccessToken = async () => {
const { clientId, clientSecret } = await inquirer.prompt([
{ name: "clientId" },
{ name: "clientSecret" }
]);
const res = await got.post("https://us.battle.net/oauth/token", {
form: true,
auth: `${clientId}:${clientSecret}`,
body: { grant_type: "client_credentials" }
});
return JSON.parse(res.body).access_token;
};

const getAllQuests = async accessToken => {
const res = await got.get("https://us.api.blizzard.com/hearthstone/cards", {
json: true,
query: {
locale: "en_US",
textFilter: "<b>Secret:</b>",
access_token: accessToken
}
});
return res.body.cards;
};

const getAllCards = async () => {
const res = await got.get(
"https://api.hearthstonejson.com/v1/latest/enUS/cards.json",
{ json: true }
);
return res.body;
};

const main = async () => {
const accessToken = await getAccessToken();
const quests = await getAllQuests(accessToken);
const cards = await getAllCards();

const questTexts = {};
quests
.map(quest => {
return cards.find(c => c.dbfId === quest.id);
})
.sort((a, b) => a.id.localeCompare(b.id))
.forEach(card => {
questTexts[card.id] = card.cardClass;
});
await writeJson(
path.resolve(__dirname, "../src/data/secret-class-map.json"),
questTexts
);
};

main().catch(err => {
console.error(err);
});
43 changes: 43 additions & 0 deletions src/data/secret-class-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"AT_002": "MAGE",
"AT_060": "HUNTER",
"AT_073": "PALADIN",
"BOT_908": "PALADIN",
"CFM_026": "HUNTER",
"CFM_620": "MAGE",
"CFM_800": "PALADIN",
"DAL_570": "PALADIN",
"EX1_130": "PALADIN",
"EX1_132": "PALADIN",
"EX1_136": "PALADIN",
"EX1_287": "MAGE",
"EX1_289": "MAGE",
"EX1_294": "MAGE",
"EX1_295": "MAGE",
"EX1_379": "PALADIN",
"EX1_533": "HUNTER",
"EX1_554": "HUNTER",
"EX1_594": "MAGE",
"EX1_609": "HUNTER",
"EX1_610": "HUNTER",
"EX1_611": "HUNTER",
"FP1_018": "MAGE",
"FP1_020": "PALADIN",
"GIL_577": "HUNTER",
"GIL_903": "PALADIN",
"ICC_082": "MAGE",
"ICC_200": "HUNTER",
"KAR_004": "HUNTER",
"LOE_021": "HUNTER",
"LOE_027": "PALADIN",
"LOOT_079": "HUNTER",
"LOOT_101": "MAGE",
"LOOT_204": "ROGUE",
"LOOT_210": "ROGUE",
"LOOT_214": "ROGUE",
"TRL_400": "MAGE",
"tt_010": "MAGE",
"ULD_152": "HUNTER",
"ULD_239": "MAGE",
"UNG_024": "MAGE"
}
2 changes: 2 additions & 0 deletions src/data/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ export const secretToClass: {[id: string]: SecretClass} =
LOOT_214: SecretClass.Rogue,
TRL_400: SecretClass.Mage,
tt_010: SecretClass.Mage, // eslint-disable-line @typescript-eslint/camelcase
ULD_152: SecretClass.Hunter,
ULD_239: SecretClass.Mage,
UNG_024: SecretClass.Mage
};