summaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/guild_add.js34
-rw-r--r--views/match.js11
-rw-r--r--views/register.js16
-rw-r--r--views/view.js10
4 files changed, 23 insertions, 48 deletions
diff --git a/views/guild_add.js b/views/guild_add.js
deleted file mode 100644
index cb32dc3..0000000
--- a/views/guild_add.js
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/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/match.js b/views/match.js
index 8a04045..2dc55ec 100644
--- a/views/match.js
+++ b/views/match.js
@@ -15,13 +15,8 @@ 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) {
+ async text(match) {
let resps = [];
for(let roster of match.rosters) {
let winstr = "Won";
@@ -49,8 +44,8 @@ module.exports = class extends View {
return embed;
};
- async respond() {
- const match = await api.getMatch(this.matchid);
+ 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;
diff --git a/views/register.js b/views/register.js
index 0e5ff71..9943299 100644
--- a/views/register.js
+++ b/views/register.js
@@ -2,7 +2,8 @@
/* jshint esnext:true */
"use strict";
-const View = require("./view"),
+const emoji = require("discord-emoji"),
+ View = require("./view"),
util = require("../util"),
api = require("../api"),
strings = require("../strings"),
@@ -12,6 +13,11 @@ const RegisterView = module.exports;
// user register view
module.exports = class extends View {
+ constructor(msg, ign) {
+ super(msg);
+ this.ign = ign;
+ }
+
async text() {
return `You are now registered at VainSocial, ${this.msg.author.mention}.`;
}
@@ -22,18 +28,18 @@ module.exports = class extends View {
let reactions = {};
reactions[emoji.symbols.repeat] = async () => {
util.trackAction(this.msg, "reaction-player");
- const ign = await util.ignForUser(undefined, this.msg.author.id);
- await new PlayerView(this.msg, ign).respond();
+ await new PlayerView(this.msg, this.ign).respond();
};
return reactions;
}
async respond() {
- await api.setUser(msg.author.id, ign);
+ console.log("************************");
+ console.log(await this.text());
this.response = await util.respond(this.msg,
await this.text(), this.response);
if (!this.hasButtons) {
await util.reactionButtons(this.response,
- await this.buttons(player, matches));
+ await this.buttons());
this.hasButtons = true;
}
return this.response;
diff --git a/views/view.js b/views/view.js
index 3d3ae38..771e3db 100644
--- a/views/view.js
+++ b/views/view.js
@@ -33,7 +33,15 @@ module.exports = class {
// reply with embed + buttons
this.response = await util.respond(this.msg,
await this.embed(), this.response);
- await util.reactionButtons(this.response, await this.buttons(), this.msg);
+ if (!this.hasButtons) {
+ await util.reactionButtons(this.response, await this.buttons(), this.msg);
+ this.hasButtons = true;
+ }
+ return this.response;
+ }
+ async error(text) {
+ // reply with error
+ this.response = await util.respond(this.msg, text, this.response);
return this.response;
}
};