summaryrefslogtreecommitdiff
path: root/views/match.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-12-30 13:11:06 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2017-12-30 13:11:06 +0100
commitc6c5027865743328d0542246fef70e0fafe0f0f1 (patch)
tree9348d4afa900c170aa534f602b6f7a823292a831 /views/match.js
parentabd33f47fbbcc92610b83341c61f5d1911eed590 (diff)
parent1881a2ecd48be772fd83b20068fe9946f1365eeb (diff)
downloaddiscordbot-c6c5027865743328d0542246fef70e0fafe0f0f1.tar.gz
discordbot-c6c5027865743328d0542246fef70e0fafe0f0f1.zip
Merge branch 'master' into developdevelop
Diffstat (limited to 'views/match.js')
-rw-r--r--views/match.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/views/match.js b/views/match.js
new file mode 100644
index 0000000..2dc55ec
--- /dev/null
+++ b/views/match.js
@@ -0,0 +1,53 @@
+#!/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 {
+ // return [[title, text], …] for rosters
+ 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(matchid) {
+ const match = await api.getMatch(matchid);
+ this.response = await util.respond(this.msg,
+ await this.embed(match), this.response);
+ return this.response;
+ };
+}