summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-08 23:15:33 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-08 23:15:33 +0200
commit31b4764cd5233acb25f4d0027261fe83eaad6ec7 (patch)
tree75e7c33b8284d711fb9208154a1d8db8b931a0f3 /commands
parentf3aa08e72c6ffdb942ea06e21ac19e28b8cd5550 (diff)
downloaddiscordbot-31b4764cd5233acb25f4d0027261fe83eaad6ec7.tar.gz
discordbot-31b4764cd5233acb25f4d0027261fe83eaad6ec7.zip
rewrite the whole thing (wip)
Diffstat (limited to 'commands')
-rw-r--r--commands/vainsocial/about.js17
-rw-r--r--commands/vainsocial/guild_add.js58
-rw-r--r--commands/vainsocial/guild_create.js8
-rw-r--r--commands/vainsocial/guild_view.js18
-rw-r--r--commands/vainsocial/match.js21
-rw-r--r--commands/vainsocial/matches.js18
-rw-r--r--commands/vainsocial/me.js30
-rw-r--r--commands/vainsocial/user.js18
8 files changed, 93 insertions, 95 deletions
diff --git a/commands/vainsocial/about.js b/commands/vainsocial/about.js
index 22d7fb4..c452d87 100644
--- a/commands/vainsocial/about.js
+++ b/commands/vainsocial/about.js
@@ -4,7 +4,7 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- responses = require("../../responses");
+ util = require("../../util");
module.exports = class ShowAboutCommand extends Commando.Command {
constructor(client) {
@@ -16,6 +16,19 @@ module.exports = class ShowAboutCommand extends Commando.Command {
});
}
async run(msg) {
- await responses.showAbout(msg);
+ util.trackAction(msg, "about");
+ await msg.embed(util.vainsocialEmbed("About VainSocial", "", "about")
+ .setDescription(
+ `Built by the VainSocial development team using the MadGlory API.
+ Currently running on ${msg.client.guilds.size} servers.`)
+ .addField("Website",
+ ROOTURL + util.track("about"), true)
+ .addField("Bot invite link",
+ "https://discordapp.com/oauth2/authorize?&client_id=287297889024213003&scope=bot&permissions=52288", true)
+ .addField("Developer Discord invite",
+ "https://discord.gg/txTchJY", true)
+ .addField("Twitter",
+ "https://twitter.com/vainsocial", true)
+ );
}
};
diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js
index 531d3dd..0021360 100644
--- a/commands/vainsocial/guild_add.js
+++ b/commands/vainsocial/guild_add.js
@@ -6,7 +6,8 @@ const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
Promise = require("bluebird"),
api = require("../../api"),
- util = require("../../util");
+ util = require("../../util"),
+ GuildAddView = require("../../views/guild_add");
module.exports = class AddGuildMemberCommand extends Commando.Command {
constructor(client) {
@@ -26,48 +27,21 @@ Register IGNs to your Guild.
// register a VainSocial Guild to a Discord account
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-add");
- let response, total_progress = "";
-
- async function progress(part, final=false) {
- response = await util.respond(msg,
- total_progress + "\n" + part, response);
- if (final) total_progress += "\n" + part;
- }
-
- // for each IGN
- await Promise.each(args, async (user) => {
- await progress(`Adding ${user}…\n`);
- // make sure player exists in db
- let player = await api.getPlayer(user);
- if (player == undefined) {
- await progress(`Loading ${user}'s data into VainSocial…`);
- // if not, wait for backend to fetch name <-> api_id
- // - not interested in match history (hence no update),
- const waiter = api.subscribeUpdates(user);
- await api.searchPlayer(user);
-
- 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;
- }
- }
- } else {
- await api.updatePlayer(user);
+ let playersData = {};
+ 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 api.upsearchPlayer(args[idx]);
+ let success = false;
+ while (await waiter.next() != undefined) {
+ playersData[args[idx]] = await api.getPlayer(args[idx]);
+ await guildAddView.respond();
+ success = true;
+ }
+ if (success) {
+ await api.addToGuild(msg.author.id, args[idx]);
}
-
- // all good, register to self guild
- await api.addToGuild(msg.author.id, user);
- await progress(`Added ${user}.`, true);
});
- await progress(oneLine`
-Guild members have been added.
-You can now use ${util.usg(msg, "vgview")} for an overview.
-`, true);
}
};
diff --git a/commands/vainsocial/guild_create.js b/commands/vainsocial/guild_create.js
index 1e5a368..ad8d0e7 100644
--- a/commands/vainsocial/guild_create.js
+++ b/commands/vainsocial/guild_create.js
@@ -4,8 +4,9 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
+ util = require("../../util"),
api = require("../../api"),
- util = require("../../util");
+ GuildCreateView = require("../../views/guild_create");
module.exports = class RegisterGuildCommand extends Commando.Command {
constructor(client) {
@@ -47,14 +48,13 @@ Create a Guild with your VainSocial profile as leader.
// register a VainSocial Guild to a Discord account
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-create");
+ // TODO error handling
await api.post("/guild", {
shard_id: args.region,
name: args.name,
identifier: args.tag,
user_token: msg.author.id
});
- await msg.reply(oneLine`
-You can now use ${util.usg(msg, "vgadd")} to add members to your Guild.
-`);
+ await new GuildCreateView(msg, msg.author.id).respond();
}
};
diff --git a/commands/vainsocial/guild_view.js b/commands/vainsocial/guild_view.js
index 835b717..7deb66f 100644
--- a/commands/vainsocial/guild_view.js
+++ b/commands/vainsocial/guild_view.js
@@ -4,8 +4,8 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- api = require("../../api"),
- util = require("../../util");
+ util = require("../../util"),
+ GuildOverviewView = require("../../views/guild");
module.exports = class ViewGuildCommand extends Commando.Command {
constructor(client) {
@@ -33,18 +33,6 @@ Show a summary of your Guild.
// show Guild details
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-view");
- // get this user's guild
- const guild = await api.getGuild(msg.author.id);
- if (guild == undefined) {
- await msg.reply("You are not registered in any guilds.");
- return;
- }
- // build response
- let response = "";
- response += `${guild.name} (${guild.shard_id})\n`;
- guild.members.forEach((member) => {
- response += `${member.player.name}: ${member.fame} VainSocial Fame\n`;
- });
- await msg.say(response);
+ await new GuildOverviewView(msg, msg.author.id).respond();
}
};
diff --git a/commands/vainsocial/match.js b/commands/vainsocial/match.js
index ba24baf..c3d2906 100644
--- a/commands/vainsocial/match.js
+++ b/commands/vainsocial/match.js
@@ -4,7 +4,10 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- responses = require("../../responses");
+ util = require("../../util"),
+ api = require("../../api"),
+ strings = require("../../strings"),
+ MatchView = require("../../views/match");
module.exports = class ShowMatchCommand extends Commando.Command {
constructor(client) {
@@ -38,6 +41,20 @@ module.exports = class ShowMatchCommand extends Commando.Command {
});
}
async run(msg, args) {
- await responses.showMatch(msg, args);
+ util.trackAction(msg, "vainsocial-match", args.name);
+ const ign = await util.ignForUser(args.name, msg.author.id);
+ if (ign == undefined) return await msg.say(strings.unknown(msg));
+
+ const participations = await api.getMatches(ign);
+ if (args.number > participations.length)
+ return await msg.say(strings.tooFewMatches(ign));
+ const matchView = new MatchView(msg,
+ participations[args.number-1].match_api_id);
+ // wait for BE update
+ const waiter = api.subscribeUpdates(ign);
+ await api.upsearchPlayer(ign);
+
+ do await matchView.respond();
+ while (await waiter.next() != undefined);
}
};
diff --git a/commands/vainsocial/matches.js b/commands/vainsocial/matches.js
index 7eaa513..0197b8b 100644
--- a/commands/vainsocial/matches.js
+++ b/commands/vainsocial/matches.js
@@ -4,7 +4,10 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- responses = require("../../responses");
+ util = require("../../util"),
+ api = require("../../api"),
+ strings = require("../../strings"),
+ MatchesView = require("../../views/matches");
module.exports = class ShowMatchesCommand extends Commando.Command {
constructor(client) {
@@ -29,6 +32,17 @@ module.exports = class ShowMatchesCommand extends Commando.Command {
});
}
async run(msg, args) {
- await responses.showMatches(msg, args);
+ util.trackAction(msg, "vainsocial-matches", args.name);
+ const ign = await util.ignForUser(args.name, msg.author.id);
+ if (ign == undefined) return await strings.unknown(msg);
+
+ // peek
+ const matchesView = new MatchesView(msg, ign);
+ // wait for BE update
+ const waiter = api.subscribeUpdates(ign);
+ await api.upsearchPlayer(ign);
+
+ do await matchesView.respond();
+ while (await waiter.next() != undefined);
}
};
diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js
index 76619bb..e17afea 100644
--- a/commands/vainsocial/me.js
+++ b/commands/vainsocial/me.js
@@ -32,31 +32,9 @@ Store your in game name for quicker access to other commands and for Guild manag
}
// register a Discord account at VainSocial
async run(msg, args) {
- const ign = args.name;
- util.trackAction(msg, "vainsocial-me", ign);
- 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 create a Guild with ${util.usg(msg, "vgcreate")}.
-`);
+ util.trackAction(msg, "vainsocial-me", args.name);
+ await api.upsearchPlayer(ign);
+ await api.subscribeUpdates(ign).next();
+ await new RegisterView(msg).respond();
}
};
diff --git a/commands/vainsocial/user.js b/commands/vainsocial/user.js
index 43aecac..bfcc1a0 100644
--- a/commands/vainsocial/user.js
+++ b/commands/vainsocial/user.js
@@ -4,7 +4,11 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- responses = require("../../responses");
+ emoji = require("discord-emoji"),
+ util = require("../../util"),
+ strings = require("../../strings"),
+ api = require("../../api"),
+ PlayerView = require("../../views/player");
module.exports = class ShowUserCommand extends Commando.Command {
constructor(client) {
@@ -31,6 +35,16 @@ Display VainSocial lifetime statistics from Vainglory
});
}
async run(msg, args) {
- await responses.showUser(msg, args);
+ util.trackAction(msg, "vainsocial-user", args.name);
+ const ign = await util.ignForUser(args.name, msg.author.id);
+ if (ign == undefined) return await msg.say(strings.unknown(msg));
+
+ const playerView = new PlayerView(msg, ign);
+ // wait for BE update
+ const waiter = api.subscribeUpdates(ign);
+ await api.upsearchPlayer(ign);
+
+ do await playerView.respond();
+ while (await waiter.next() != undefined);
}
};