summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-09 18:37:02 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-09 18:37:02 +0200
commitdff1dca205950fd0eaf643b18e3998c924f3f9a5 (patch)
tree2b23f33ef21df451a256b5c74e36ad475a99a67d
parent0ee8e0e5239e3f76911834da54d2c72a4a149804 (diff)
downloaddiscordbot-dff1dca205950fd0eaf643b18e3998c924f3f9a5.tar.gz
discordbot-dff1dca205950fd0eaf643b18e3998c924f3f9a5.zip
try to fix async issue, kick players
-rw-r--r--api.js19
-rw-r--r--commands/vainsocial/guild_add.js14
-rw-r--r--commands/vainsocial/guild_update.js2
3 files changed, 29 insertions, 6 deletions
diff --git a/api.js b/api.js
index c809309..2d61a01 100644
--- a/api.js
+++ b/api.js
@@ -61,6 +61,16 @@ module.exports.postFE = module.exports.post = async (url, params={}, cachekey=un
});
}
+// send a DELETE and optionally bust cache
+module.exports.deleteFE = module.exports.post = async (url, params={}, cachekey=undefined) => {
+ if (cachekey) cache.del(cachekey);
+ return await request.delete(API_FE_URL + url, {
+ form: params,
+ json: true,
+ forever: true
+ });
+}
+
module.exports.postBE = module.exports.backend = async (url) => {
return await request.post({
uri: API_BE_URL + url,
@@ -204,7 +214,14 @@ module.exports.addToGuild = async (token, member) => {
user_token: token,
member_name: member
}, "guild+" + token);
- cache.del("guild+" + token);
+ return membership;
+}
+
+// kick from guild
+module.exports.removeFromGuild = async (token, member) => {
+ const membership = await api.deleteFE("/guild/members/" + member, {
+ user_token: token
+ }, "guild+" + token);
return membership;
}
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())) {