summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/vainsocial/guild_add.js16
-rw-r--r--commands/vainsocial/guild_create.js18
-rw-r--r--commands/vainsocial/guild_view.js12
-rw-r--r--commands/vainsocial/me.js13
4 files changed, 18 insertions, 41 deletions
diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js
index 7f6aac7..8dc2ab8 100644
--- a/commands/vainsocial/guild_add.js
+++ b/commands/vainsocial/guild_add.js
@@ -5,12 +5,9 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
Promise = require("bluebird"),
- request = require("request-promise"),
api = require("../../api"),
util = require("../../util");
-const API_FE_URL = process.env.API_FE_URL || "http://vainsocial.dev/bot/api";
-
module.exports = class AddGuildMemberCommand extends Commando.Command {
constructor(client) {
super(client, {
@@ -44,9 +41,11 @@ Register IGNs to your Guild.
let player = await api.getPlayer(user);
if (player == undefined) {
await progress(`Loading ${user}'s data into VainSocial…`);
- // if not, wait for backend to fetch
+ // 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) {
@@ -63,12 +62,9 @@ Register IGNs to your Guild.
}
// all good, register to self guild
- await request.post(API_FE_URL + "/guild/members", {
- forever: true,
- form: {
- user_token: msg.author.id,
- member_name: user
- }
+ await api.post("/guild/members", {
+ user_token: msg.author.id,
+ member_name: user
});
await progress(`Added ${user}.`, true);
});
diff --git a/commands/vainsocial/guild_create.js b/commands/vainsocial/guild_create.js
index 9114703..1e5a368 100644
--- a/commands/vainsocial/guild_create.js
+++ b/commands/vainsocial/guild_create.js
@@ -4,11 +4,9 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- request = require("request-promise"),
+ api = require("../../api"),
util = require("../../util");
-const API_FE_URL = process.env.API_FE_URL || "http://vainsocial.dev/bot/api";
-
module.exports = class RegisterGuildCommand extends Commando.Command {
constructor(client) {
super(client, {
@@ -49,15 +47,11 @@ 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");
- console.log(API_FE_URL + "/guild");
- await request.post(API_FE_URL + "/guild", {
- forever: true,
- form: {
- shard_id: args.region,
- name: args.name,
- identifier: args.tag,
- user_token: msg.author.id
- }
+ 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.
diff --git a/commands/vainsocial/guild_view.js b/commands/vainsocial/guild_view.js
index c459590..e692402 100644
--- a/commands/vainsocial/guild_view.js
+++ b/commands/vainsocial/guild_view.js
@@ -4,11 +4,9 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- request = require("request-promise"),
+ api = require("../../api"),
util = require("../../util");
-const API_FE_URL = process.env.API_FE_URL || "http://vainsocial.dev/bot/api";
-
module.exports = class ViewGuildCommand extends Commando.Command {
constructor(client) {
super(client, {
@@ -36,13 +34,7 @@ Show a summary of your Guild.
async run(msg, args) {
util.trackAction(msg, "vainsocial-guild-view");
// get this user's guild
- const guild = await request(API_FE_URL + "/guild", {
- forever: true,
- json: true,
- qs: {
- user_token: msg.author.id
- }
- });
+ const guild = await api.get("/guild", { user_token: msg.author.id });
if (guild == undefined) {
await msg.reply("You are not registered in any guilds.");
return;
diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js
index 02818be..400bc70 100644
--- a/commands/vainsocial/me.js
+++ b/commands/vainsocial/me.js
@@ -4,11 +4,9 @@
const Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
- request = require("request-promise"),
+ api = require("../../api"),
util = require("../../util");
-const API_FE_URL = process.env.API_FE_URL || "http://vainsocial.dev/bot/api";
-
module.exports = class RegisterUserCommand extends Commando.Command {
constructor(client) {
super(client, {
@@ -36,12 +34,9 @@ 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 request.post(API_FE_URL + "/user", {
- forever: true,
- form: {
- name: ign,
- user_token: msg.author.id
- }
+ await api.post("/user", {
+ name: ign,
+ user_token: msg.author.id
});
await msg.reply(oneLine`
You are now able to use ${util.usg(msg, "v")} to access your profile faster.