summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-09 19:47:50 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-09 19:47:50 +0200
commitd158b9dabfc8b6c9a6c13e3307be455957b95a98 (patch)
treebae84669e3f18870d5d6b393210a9035ffbfc50a
parent343648f0e9faefaf13ffa3e039b92d67970c31fc (diff)
downloaddiscordbot-d158b9dabfc8b6c9a6c13e3307be455957b95a98.tar.gz
discordbot-d158b9dabfc8b6c9a6c13e3307be455957b95a98.zip
fix progress reports
-rw-r--r--commands/vainsocial/guild_add.js28
-rw-r--r--commands/vainsocial/guild_rm.js14
-rw-r--r--commands/vainsocial/guild_update.js12
-rw-r--r--views/guild_progress.js7
4 files changed, 34 insertions, 27 deletions
diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js
index 75eb5f3..c1de856 100644
--- a/commands/vainsocial/guild_add.js
+++ b/commands/vainsocial/guild_add.js
@@ -26,25 +26,31 @@ Register IGNs to your Guild.
}
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-add");
- let playersData = {};
+ let playersStatus = {};
const playersWaiters = args.map((name) => api.subscribeUpdates(name)),
- guildAddView = new GuildAddView(msg, playersData);
+ guildAddView = new GuildAddView(msg, playersStatus);
// create waiter dict & data dict
await Promise.each(playersWaiters, async (waiter, idx) => {
await api.upsearchPlayer(args[idx]);
let success = false;
- while (["stats_update", "matches_update", undefined].indexOf(
- await waiter.next())) {
- try {
- playersData[args[idx]] = await api.getPlayer(args[idx]);
- success = true;
- } catch (err) {
- playersData[args[idx]] = undefined;
- }
- await guildAddView.respond();
+ try {
+ do {
+ try {
+ await api.getPlayer(args[idx]);
+ playersStatus[args[idx]] = "Loading…";
+ success = true;
+ } catch (err) { }
+ await guildAddView.respond();
+ } while (["stats_update", "matches_update", undefined]
+ .indexOf(await waiter.next()));
+ } catch (err) {
+ console.error(err);
+ playersStatus[args[idx]] = err.error.err;
+ success = false;
}
if (success) {
await api.addToGuild(msg.author.id, args[idx]);
+ playersStatus[args[idx]] = "Loaded.";
}
});
await guildAddView.respond("Your Guild members were added.");
diff --git a/commands/vainsocial/guild_rm.js b/commands/vainsocial/guild_rm.js
index 24bad36..4857c44 100644
--- a/commands/vainsocial/guild_rm.js
+++ b/commands/vainsocial/guild_rm.js
@@ -26,12 +26,18 @@ Remove an IGN from your Guild.
}
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-rm");
- let playersData = {};
- const guildRmView = new GuildRmView(msg, playersData);
+ let playersStatus = {};
+ const guildRmView = new GuildRmView(msg, playersStatus);
try {
await Promise.each(args, async (name) => {
- await api.removeFromGuild(msg.author.id, name);
- await guildRmView.respond();
+ try {
+ playersStatus[name] = "Removing…";
+ await api.removeFromGuild(msg.author.id, name);
+ playersStatus[name] = "Removed.";
+ await guildRmView.respond();
+ } catch (err) {
+ playersStatus[name] = err.error.err;
+ }
});
} catch (err) {
console.error(err);
diff --git a/commands/vainsocial/guild_update.js b/commands/vainsocial/guild_update.js
index f0360ea..c3163be 100644
--- a/commands/vainsocial/guild_update.js
+++ b/commands/vainsocial/guild_update.js
@@ -27,11 +27,10 @@ Update the match history for all your Guild members.
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-update");
// obj of ign: player
- let playersData = {};
+ let playersStatus = {};
// collect an array of IGNs
let names, guild;
- const guildUpdateView = new GuildMembersProgressView(msg,
- playersData);
+ const guildUpdateView = new GuildMembersProgressView(msg, playersStatus);
try {
guild = await api.getGuild(msg.author.id);
names = guild.members.map((m) => m.player.name);
@@ -44,15 +43,14 @@ Update the match history for all your Guild members.
// create waiter dict & data dict
await Promise.each(playersWaiters, async (waiter, idx) => {
await api.updatePlayer(names[idx]);
- let success = false;
while (["stats_update", undefined].indexOf(await waiter.next())) {
try {
- playersData[names[idx]] = await api.getPlayer(names[idx]);
+ await api.getPlayer(names[idx]);
+ playersStatus[names[idx]] = "Loaded.";
} catch (err) {
- playersData[names[idx]] = undefined;
+ playersStatus[names[idx]] = "Loading…";
}
await guildUpdateView.respond();
- success = true;
}
});
await guildUpdateView.respond("Your Guild's fame is being updated…");
diff --git a/views/guild_progress.js b/views/guild_progress.js
index 163c627..b3fdeb3 100644
--- a/views/guild_progress.js
+++ b/views/guild_progress.js
@@ -16,13 +16,10 @@ module.exports = class extends View {
this.players = players;
}
- // players: obj, key=ign, value=player
+ // players: obj, key=ign, value=progress
async text(players) {
return Object.entries(players).map((tuple) =>
- (tuple[1] == undefined)?
- `Loading ${tuple[0]}…`
- : `Loaded ${tuple[0]}.`
- ).join("\n");
+ `${tuple[0]}: ${tuple[1]}`).join("\n");
}
async respond(extra="") {