summaryrefslogtreecommitdiff
path: root/views/match.js
diff options
context:
space:
mode:
Diffstat (limited to 'views/match.js')
-rw-r--r--views/match.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/views/match.js b/views/match.js
new file mode 100644
index 0000000..8a04045
--- /dev/null
+++ b/views/match.js
@@ -0,0 +1,58 @@
+#!/usr/bin/node
+/* jshint esnext:true */
+"use strict";
+
+const View = require("./view"),
+ util = require("../util"),
+ api = require("../api"),
+ strings = require("../strings"),
+ oneLine = require("common-tags").oneLine;
+
+const PREVIEW = process.env.PREVIEW != "false",
+ ROOTURL = (PREVIEW? "https://preview.vainsocial.com/":"https://vainsocial.com/");
+
+const MatchView = module.exports;
+
+// match detail view
+module.exports = class extends View {
+ constructor(msg, matchid) {
+ super(msg);
+ this.matchid = matchid;
+ }
+
+ // return [[title, text], …] for rosters
+ static async text(match) {
+ let resps = [];
+ for(let roster of match.rosters) {
+ let winstr = "Won";
+ if (!roster.winner) winstr = "Lost";
+ let rosterstr = `${roster.side} - \`${roster.hero_kills}\` Kills - ${winstr}`;
+ let teamstr = "";
+ for(let participant of roster.participants) {
+ const hero = await api.mapActor(participant.actor),
+ emojiScore = strings.emojifyScore(participant.stats.impact_score);
+ teamstr += `
+\`${hero}\`, [${participant.player.name}](${ROOTURL}player/${participant.player.name}${util.track("match-detail")}) \`T${Math.floor(participant.skill_tier/3+1)}\` | \`${participant.stats.kills}/${participant.stats.deaths}/${participant.stats.assists}\`, \`${Math.floor(participant.stats.farm)}\`, Score ${emojiScore} \`${Math.floor(100 * participant.stats.impact_score)}%\``;
+ }
+ resps.push([rosterstr, teamstr]);
+ }
+ return resps;
+ }
+
+ async embed(match) {
+ let embed = util.vainsocialEmbed(`${match.game_mode}, ${match.duration} minutes`,
+ "matches/" + match.api_id , "vainsocial-match")
+ .setTimestamp(new Date(match.created_at));
+ (await this.text(match)).forEach(([title, text]) => {
+ embed.addField(title, text, true);
+ });
+ return embed;
+ };
+
+ async respond() {
+ const match = await api.getMatch(this.matchid);
+ this.response = await util.respond(this.msg,
+ await this.embed(match), this.response);
+ return this.response;
+ };
+}