diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-09 13:24:41 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-09 13:24:41 +0200 |
| commit | 54b59d1168e79c8706b164194bc1a48ec49726e4 (patch) | |
| tree | 82b685a4e934ba237db3abcdde51d6f8e2c1b993 /views | |
| parent | 31b4764cd5233acb25f4d0027261fe83eaad6ec7 (diff) | |
| download | discordbot-54b59d1168e79c8706b164194bc1a48ec49726e4.tar.gz discordbot-54b59d1168e79c8706b164194bc1a48ec49726e4.zip | |
error handling
Diffstat (limited to 'views')
| -rw-r--r-- | views/guild_add.js | 34 | ||||
| -rw-r--r-- | views/match.js | 11 | ||||
| -rw-r--r-- | views/register.js | 16 | ||||
| -rw-r--r-- | views/view.js | 10 |
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; } }; |
