From 6f9173764a3c40bd252097d2029c82a0401a42ec Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 19 Apr 2017 12:11:12 +0200 Subject: use actor - name mapping --- api.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'api.js') diff --git a/api.js b/api.js index 24c9a9a..a5d42af 100644 --- a/api.js +++ b/api.js @@ -66,13 +66,23 @@ function subscribe(topic, channel) { async function getMappings() { return await cache.wrap("mappings", async () => { let mapping = new Map(); - await Promise.map( - ["gamemode"], async (table) => { - mapping[table] = new Map(); - (await getMap(table)).map( - (map) => mapping[table][map["id"]] = map["name"]) - } - ); + await Promise.all([ + Promise.map( + ["gamemode"], async (table) => { + mapping[table] = new Map(); + (await getMap(table)).map( + (map) => mapping[table][map["id"]] = map["name"]) + } + ), + // name <-> API name + Promise.map( + ["hero"], async (table) => { + mapping[table] = new Map(); + (await getMap(table)).map( + (map) => mapping[table][map["api_name"]] = map["name"]) + } + ) + ]); return mapping; }, { ttl: 60 * 30 }); } @@ -81,6 +91,10 @@ module.exports.mapGameMode = async function(id) { return (await getMappings())["gamemode"][id]; } +module.exports.mapActor = async function(api_name) { + return (await getMappings())["hero"][api_name]; +} + // return a set of IGN of supporters module.exports.getGamers = async function() { return await cache.wrap("gamers", async () => { -- cgit v1.3.1