1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
};
}
|