summaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/guild.js11
-rw-r--r--views/guild_create.js2
-rw-r--r--views/guild_progress.js33
-rw-r--r--views/guild_update.js34
-rw-r--r--views/matches.js7
-rw-r--r--views/player.js19
-rw-r--r--views/register.js6
7 files changed, 84 insertions, 28 deletions
diff --git a/views/guild.js b/views/guild.js
index a5eedef..23c2afe 100644
--- a/views/guild.js
+++ b/views/guild.js
@@ -24,16 +24,11 @@ module.exports = class extends View {
"", "vainsocial-guild-view")
.setDescription(await this.text(guild.members));
return embed;
- };
+ }
- async respond(guild) {
- if (guild == undefined) {
- this.response = await util.respond(this.msg,
- strings.notRegistered, this.response);
- return this.response;
- }
+ async respond(guild, extra="") {
this.response = await util.respond(this.msg,
await this.embed(guild), this.response);
return this.response;
- };
+ }
}
diff --git a/views/guild_create.js b/views/guild_create.js
index 8e7be81..38720e1 100644
--- a/views/guild_create.js
+++ b/views/guild_create.js
@@ -38,7 +38,7 @@ module.exports = class extends View {
// TODO move to super class
async respond() {
this.response = await util.respond(this.msg,
- await this.text(), this.response);
+ await this.text() + "\n" + await this.help(), this.response);
if (!this.hasButtons) {
await util.reactionButtons(this.response,
await this.buttons());
diff --git a/views/guild_progress.js b/views/guild_progress.js
new file mode 100644
index 0000000..163c627
--- /dev/null
+++ b/views/guild_progress.js
@@ -0,0 +1,33 @@
+#!/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 GuildMembersProgressView = module.exports;
+
+module.exports = class extends View {
+ constructor(msg, players) {
+ super(msg);
+ this.players = players;
+ }
+
+ // players: obj, key=ign, value=player
+ async text(players) {
+ return Object.entries(players).map((tuple) =>
+ (tuple[1] == undefined)?
+ `Loading ${tuple[0]}…`
+ : `Loaded ${tuple[0]}.`
+ ).join("\n");
+ }
+
+ async respond(extra="") {
+ this.response = await util.respond(this.msg,
+ await this.text(this.players) + "\n" + extra, this.response);
+ return this.response;
+ };
+}
diff --git a/views/guild_update.js b/views/guild_update.js
new file mode 100644
index 0000000..cb32dc3
--- /dev/null
+++ b/views/guild_update.js
@@ -0,0 +1,34 @@
+#!/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 GuildAddView = module.exports;
+
+// match detail view
+module.exports = class extends View {
+ constructor(msg, players) {
+ super(msg);
+ this.players = players;
+ }
+
+ // players: obj, key=ign, value=player
+ async text(players) {
+ return Object.entries(players).map((tuple) =>
+ (tuple[1] == undefined)?
+ `Loading ${tuple[0]}…`
+ : `Loaded ${tuple[0]}.`
+ ).join("\n");
+ }
+
+ async respond() {
+ this.response = await util.respond(this.msg,
+ await this.text(this.players), this.response);
+ return this.response;
+ };
+}
diff --git a/views/matches.js b/views/matches.js
index 279bf9c..a79654b 100644
--- a/views/matches.js
+++ b/views/matches.js
@@ -39,8 +39,8 @@ Score | ${emojiScore} \`${Math.floor(100 * participant.stats.impact_score)}%\`
const matchesPart = matches.slice(0, MATCH_HISTORY_LEN);
// build embed
- let embed = util.vainsocialEmbed(
- this.ign, "player/" + this.ign, "vainsocial-matches")
+ let embed = util.vainsocialEmbed(this.ign,
+ "player/" + this.ign, "vainsocial-matches")
.setDescription(`Last ${matchesPart.length} casual and ranked matches.\n`
+ await this.help())
.setTimestamp(new Date(matchesPart[0].created_at));
@@ -60,9 +60,8 @@ Score | ${emojiScore} \`${Math.floor(100 * participant.stats.impact_score)}%\`
let reactions = {};
matchesPart.forEach((m, idx) =>
reactions[strings.emojiCount[idx]] = async () => {
- console.log("react");
util.trackAction(this.msg, "reaction-match", m.match_api_id);
- await new MatchView(this.msg, m.match_api_id).respond();
+ await new MatchView(this.msg).respond(m.match_api_id);
});
return reactions;
}
diff --git a/views/player.js b/views/player.js
index ec5d38b..a481c69 100644
--- a/views/player.js
+++ b/views/player.js
@@ -72,7 +72,7 @@ ${emoji.symbols["1234"]} or ${util.usg(this.msg, "vh " + this.ign)} for more*`;
let reactions = {};
reactions[emoji.symbols.information_source] = async () => {
util.trackAction(this.msg, "reaction-match", player.name);
- await new MatchView(this.msg, matches[0].match_api_id).respond();
+ await new MatchView(this.msg).respond(matches[0].match_api_id);
};
reactions[emoji.symbols["1234"]] = async () => {
util.trackAction(this.msg, "reaction-matches", player.name);
@@ -82,16 +82,13 @@ ${emoji.symbols["1234"]} or ${util.usg(this.msg, "vh " + this.ign)} for more*`;
}
async respond() {
- const [player, matches] = await Promise.all([
- api.getPlayer(this.ign),
- api.getMatches(this.ign)
- ]);
- if (player == undefined) {
- this.response = await util.respond(this.msg,
- strings.loading(this.ign), this.response);
- return this.response;
- }
- if (matches.length == 0) {
+ let player, matches;
+ try {
+ [player, matches] = await Promise.all([
+ api.getPlayer(this.ign),
+ api.getMatches(this.ign)
+ ]);
+ } catch (err) {
this.response = await util.respond(this.msg,
strings.loading(this.ign), this.response);
return this.response;
diff --git a/views/register.js b/views/register.js
index 9943299..1df3bf1 100644
--- a/views/register.js
+++ b/views/register.js
@@ -19,7 +19,7 @@ module.exports = class extends View {
}
async text() {
- return `You are now registered at VainSocial, ${this.msg.author.mention}.`;
+ return `You are now registered at VainSocial, @${this.msg.author.tag}.`;
}
async help() {
return `*${emoji.symbols.repeat} or ${util.usg(this.msg, "v")} to view your profile, ${util.usg(this.msg, "vgcreate")} to create a Guild*`
@@ -33,10 +33,8 @@ module.exports = class extends View {
return reactions;
}
async respond() {
- console.log("************************");
- console.log(await this.text());
this.response = await util.respond(this.msg,
- await this.text(), this.response);
+ await this.text() + "\n" + await this.help(), this.response);
if (!this.hasButtons) {
await util.reactionButtons(this.response,
await this.buttons());