From dff1dca205950fd0eaf643b18e3998c924f3f9a5 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 9 May 2017 18:37:02 +0200 Subject: try to fix async issue, kick players --- commands/vainsocial/guild_add.js | 14 ++++++++++---- commands/vainsocial/guild_update.js | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'commands') diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js index 8fe952c..75eb5f3 100644 --- a/commands/vainsocial/guild_add.js +++ b/commands/vainsocial/guild_add.js @@ -30,17 +30,23 @@ Register IGNs to your Guild. const playersWaiters = args.map((name) => api.subscribeUpdates(name)), guildAddView = new GuildAddView(msg, playersData); // create waiter dict & data dict - await Promise.map(playersWaiters, async (waiter, idx) => { + await Promise.each(playersWaiters, async (waiter, idx) => { await api.upsearchPlayer(args[idx]); let success = false; - while (["stats_update", undefined].indexOf(await waiter.next())) { - playersData[args[idx]] = await api.getPlayer(args[idx]); + 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(); - success = true; } if (success) { await api.addToGuild(msg.author.id, args[idx]); } }); + await guildAddView.respond("Your Guild members were added."); } }; diff --git a/commands/vainsocial/guild_update.js b/commands/vainsocial/guild_update.js index 7d36b0e..f0360ea 100644 --- a/commands/vainsocial/guild_update.js +++ b/commands/vainsocial/guild_update.js @@ -42,7 +42,7 @@ Update the match history for all your Guild members. // update all the IGNs const playersWaiters = names.map((name) => api.subscribeUpdates(name)); // create waiter dict & data dict - await Promise.map(playersWaiters, async (waiter, idx) => { + await Promise.each(playersWaiters, async (waiter, idx) => { await api.updatePlayer(names[idx]); let success = false; while (["stats_update", undefined].indexOf(await waiter.next())) { -- cgit v1.3.1