summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-04-19 12:11:12 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-04-19 12:11:12 +0200
commit6f9173764a3c40bd252097d2029c82a0401a42ec (patch)
tree1ece95e3c36c6fa49fbb77dee9935c4644ed0f05
parent65da4cba0053bc6ee6f5442a45022bf5b4198e70 (diff)
downloaddiscordbot-6f9173764a3c40bd252097d2029c82a0401a42ec.tar.gz
discordbot-6f9173764a3c40bd252097d2029c82a0401a42ec.zip
use actor - name mapping
-rw-r--r--api.js28
-rw-r--r--responses.js22
2 files changed, 34 insertions, 16 deletions
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 () => {
diff --git a/responses.js b/responses.js
index 39369ed..e28af93 100644
--- a/responses.js
+++ b/responses.js
@@ -55,10 +55,11 @@ function emojifyScore(score) {
// return a match overview string
async function formatMatch(participant) {
let winstr = "Won",
+ hero = await api.mapActor(participant.actor),
game_mode = await api.mapGameMode(participant.game_mode_id);
if (!participant.winner) winstr = "Lost";
return `
-${winstr} ${game_mode} with \`${participant.actor.replace(/\*/g, "")}\`
+${winstr} ${game_mode} with \`${hero}\`
KDA, CS | \`${participant.stats.kills}/${participant.stats.deaths}/${participant.stats.assists}\`, \`${Math.round(participant.stats.farm)}\`
Kill Participation | \`${Math.floor(100 * participant.stats.kill_participation)}%\`
Score | ${emojifyScore(participant.stats.impact_score)} \`${Math.floor(100 * participant.stats.impact_score)}%\`
@@ -72,8 +73,9 @@ async function formatMatchDetail(match) {
let rosterstr = `${roster.side} - \`${roster.hero_kills}\` Kills`;
let teamstr = "";
for(let participant of roster.participants) {
+ const hero = await api.mapActor(participant.actor);
teamstr += `
-\`${participant.actor.replace(/\*/g, "")}\`, [${participant.player.name}](https://vainsocial.com/player/${participant.player.name}) \`T${Math.floor(participant.skill_tier/3)}\` | \`${participant.stats.kills}/${participant.stats.deaths}/${participant.stats.assists}\`, \`${Math.floor(participant.stats.farm)}\`, Score ${emojifyScore(participant.stats.impact_score)} \`${Math.floor(100 * participant.stats.impact_score)}%\``;
+\`${hero}\`, [${participant.player.name}](https://vainsocial.com/player/${participant.player.name}) \`T${Math.floor(participant.skill_tier/3)}\` | \`${participant.stats.kills}/${participant.stats.deaths}/${participant.stats.assists}\`, \`${Math.floor(participant.stats.farm)}\`, Score ${emojifyScore(participant.stats.impact_score)} \`${Math.floor(100 * participant.stats.impact_score)}%\``;
}
strings.push([rosterstr, teamstr]);
}
@@ -81,8 +83,8 @@ async function formatMatchDetail(match) {
}
// return a profile string
-function formatPlayer(player) {
- let stats = oneLine`
+async function formatPlayer(player) {
+ const stats = oneLine`
Win Rate | \`${Math.round(100 *
player.currentSeries.reduce((t, s) => t + s.wins, 0) /
player.currentSeries.reduce((t, s) => t + s.played, 0)
@@ -90,17 +92,19 @@ function formatPlayer(player) {
`,
total_kda = oneLine`
Total KDA | \`${player.stats.kills}\` / \`${player.stats.deaths}\` / \`${player.stats.assists}\`
- `,
- best_hero = "",
+ `;
+ let best_hero = "",
picks = "";
if (player.best_hero.length > 0)
best_hero = oneLine`
Best | \`${player.best_hero[0].name}\`
`;
- if (player.picks.length > 0)
+ if (player.picks.length > 0) {
+ const hero = await api.mapActor(player.picks[0].actor);
picks = oneLine`
- Favorite | \`${player.picks[0].actor.replace(/\*/g, "")}\`, \`${player.picks[0].hero_pick} picks\`
+ Favorite | \`${hero}\`, \`${player.picks[0].hero_pick} picks\`
`;
+ }
return `
${stats}
${total_kda}
@@ -255,7 +259,7 @@ ${emoji.symbols["1234"]} or ${usg(msg, "vh " + ign)} for more*`
.setThumbnail("https://vainsocial.com/images/game/skill_tiers/" +
matches.data[0].skill_tier + ".png")
.setDescription("")
- .addField("Profile", formatPlayer(player), true)
+ .addField("Profile", await formatPlayer(player), true)
.addField("Last match", await formatMatch(matches.data[0]) + moreHelp, true)
.setTimestamp(new Date(matches.data[0].created_at));
response = await respond(msg, embed, response);