summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/vainsocial/guild_add.js2
-rw-r--r--commands/vainsocial/guild_fame_calc.js2
-rw-r--r--commands/vainsocial/guild_update.js38
-rw-r--r--commands/vainsocial/me.js24
4 files changed, 60 insertions, 6 deletions
diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js
index b4aa864..531d3dd 100644
--- a/commands/vainsocial/guild_add.js
+++ b/commands/vainsocial/guild_add.js
@@ -50,7 +50,7 @@ Register IGNs to your Guild.
// wait until search success
while (true) {
notif = await waiter.next();
- if (notif == "search_success") break;
+ if (notif == "stats_update") break;
if (notif == undefined) {
// give up
await progress(`Ooops! Could not find ${user}.`, true);
diff --git a/commands/vainsocial/guild_fame_calc.js b/commands/vainsocial/guild_fame_calc.js
index fbd7469..e1ec912 100644
--- a/commands/vainsocial/guild_fame_calc.js
+++ b/commands/vainsocial/guild_fame_calc.js
@@ -11,7 +11,7 @@ module.exports = class CalculateGuildFameCommand extends Commando.Command {
constructor(client) {
super(client, {
name: "vainsocial-guildcalc",
- aliases: ["vguild-calc", "vgcalc", "vgc"],
+ aliases: ["vguild-calc", "vgcalc"],
group: "vainsocial-guild",
memberName: "vainsocial-guildcalc",
description: "Update your Guild's fame.",
diff --git a/commands/vainsocial/guild_update.js b/commands/vainsocial/guild_update.js
new file mode 100644
index 0000000..9c9fe1d
--- /dev/null
+++ b/commands/vainsocial/guild_update.js
@@ -0,0 +1,38 @@
+#!/usr/bin/node
+/* jshint esnext:true */
+"use strict";
+
+const Commando = require("discord.js-commando"),
+ oneLine = require("common-tags").oneLine,
+ Promise = require("bluebird"),
+ api = require("../../api"),
+ util = require("../../util");
+
+module.exports = class UpdateGuildCommand extends Commando.Command {
+ constructor(client) {
+ super(client, {
+ name: "vainsocial-guildupdate",
+ aliases: ["vguild-update", "vgupdate"],
+ group: "vainsocial-guild",
+ memberName: "vainsocial-guildupdate",
+ description: "Update your Guild members' data.",
+ details: oneLine`
+Update the match history for all your Guild members.
+`,
+ examples: ["vgupdate"]
+ });
+ }
+ // internal / premium: immediately call backend player refresh
+ async run(msg, args) {
+ util.trackAction(msg, "vainsocial-guild-update");
+ const guild = await api.getGuild(msg.author.id);
+ if (guild == undefined) {
+ await msg.reply("You are not registered in any guilds.");
+ return;
+ }
+ // TODO progress report
+ await Promise.map(guild.members,
+ (member) => api.upsearchPlayer(member.player.name));
+ await msg.reply("Your Guild members will be up to date soon.");
+ }
+};
diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js
index 400bc70..717e36c 100644
--- a/commands/vainsocial/me.js
+++ b/commands/vainsocial/me.js
@@ -34,10 +34,26 @@ Store your in game name for quicker access to other commands and for Guild manag
async run(msg, args) {
const ign = args.name;
util.trackAction(msg, "vainsocial-me", ign);
- await api.post("/user", {
- name: ign,
- user_token: msg.author.id
- });
+ const player = await api.getPlayer(ign);
+ // TODO refactor and build a blocking function via processor
+ // TODO respond loading
+ if (player == undefined) {
+ const waiter = api.subscribeUpdates(ign);
+ await api.searchPlayer(ign);
+
+ let success = false, notif;
+ // wait until search success
+ while (true) {
+ notif = await waiter.next();
+ if (notif == "stats_update") break;
+ if (notif == undefined) {
+ // give up
+ await progress(`Ooops! Could not find ${user}.`, true);
+ return;
+ }
+ }
+ }
+ await api.setUser(msg.author.id, ign);
await msg.reply(oneLine`
You are now able to use ${util.usg(msg, "v")} to access your profile faster.
You now have access to Guild management features.