diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-04 22:33:17 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-04 22:33:17 +0200 |
| commit | 5045641b065bfea9a0db39dd4814b2cf2269e723 (patch) | |
| tree | 08f3a90d952fb5a5655a105437d0b9de6572a6a6 /commands | |
| parent | 188e3997092a57be11574e5e121af5882dfb40ec (diff) | |
| download | discordbot-5045641b065bfea9a0db39dd4814b2cf2269e723.tar.gz discordbot-5045641b065bfea9a0db39dd4814b2cf2269e723.zip | |
fame support (wip)
Diffstat (limited to 'commands')
| -rw-r--r-- | commands/vainsocial/guild_add.js | 80 | ||||
| -rw-r--r-- | commands/vainsocial/guild_create.js | 66 | ||||
| -rw-r--r-- | commands/vainsocial/guild_view.js | 58 | ||||
| -rw-r--r-- | commands/vainsocial/me.js | 26 |
4 files changed, 225 insertions, 5 deletions
diff --git a/commands/vainsocial/guild_add.js b/commands/vainsocial/guild_add.js new file mode 100644 index 0000000..7f6aac7 --- /dev/null +++ b/commands/vainsocial/guild_add.js @@ -0,0 +1,80 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +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, { + name: "vainsocial-guildadd", + aliases: ["vguild-add", "vgadd", "vga"], + group: "vainsocial-guild", + memberName: "vainsocial-guildadd", + description: "Register a member to your Guild.", + details: oneLine` +Register IGNs to your Guild. +`, + examples: ["vgadd StormCallerSr", "vgadd StormCallerSr shutterfly"], + argsType: "multiple" + }); + } + // 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 + 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 == "search_success") break; + if (notif == undefined) { + // give up + await progress(`Ooops! Could not find ${user}.`, true); + return; + } + } + } else { + await api.updatePlayer(user); + } + + // 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 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 new file mode 100644 index 0000000..9114703 --- /dev/null +++ b/commands/vainsocial/guild_create.js @@ -0,0 +1,66 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + request = require("request-promise"), + 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, { + name: "vainsocial-guildcreate", + aliases: ["vguild-create", "vgcreate"], + group: "vainsocial-guild", + memberName: "vainsocial-guildcreate", + description: "Register a new Guild.", + details: oneLine` +Create a Guild with your VainSocial profile as leader. +`, + examples: ["vguild-create MyAmazingGuild MAG eu"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your Guild's name.", + type: "string", + min: 3 + }, { + key: "tag", + label: "tag", + prompt: "Please specify your Guild's tag.", + type: "string", + min: 3, + max: 4 + }, { + // TODO use enum + key: "region", + label: "region", + prompt: "Please specify your Guild's region.", + type: "string", + min: 2, + max: 10 + } ] + }); + } + // 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 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 new file mode 100644 index 0000000..c459590 --- /dev/null +++ b/commands/vainsocial/guild_view.js @@ -0,0 +1,58 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + request = require("request-promise"), + 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, { + name: "vainsocial-guildview", + aliases: ["vguild-view", "vgview", "vgv"], + group: "vainsocial-guild", + memberName: "vainsocial-guildview", + description: "View members of a Guild.", + details: oneLine` +Show a summary of your Guild. +`, + examples: ["vgview"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your Guild's name.", + type: "string", + min: 3, + default: "?" + } ] + }); + } + // show Guild details + 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 + } + }); + 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); + } +}; diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js index 4de7c8f..02818be 100644 --- a/commands/vainsocial/me.js +++ b/commands/vainsocial/me.js @@ -4,18 +4,21 @@ const Commando = require("discord.js-commando"), oneLine = require("common-tags").oneLine, - responses = require("../../responses"); + request = require("request-promise"), + util = require("../../util"); -module.exports = class RememberUserCommand extends Commando.Command { +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, { name: "vainsocial-me", aliases: ["vme"], group: "vainsocial", memberName: "vainsocial-me", - description: "Remembers a users's in game name.", + description: "Register a users's in game name.", details: oneLine` -Store your in game name for quicker access to other commands. +Store your in game name for quicker access to other commands and for Guild management. `, examples: ["vme shutterfly"], @@ -29,7 +32,20 @@ Store your in game name for quicker access to other commands. } ] }); } + // register a Discord account at VainSocial async run(msg, args) { - await responses.rememberUser(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 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. +`); } }; |
