diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-12-30 13:11:06 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-12-30 13:11:06 +0100 |
| commit | c6c5027865743328d0542246fef70e0fafe0f0f1 (patch) | |
| tree | 9348d4afa900c170aa534f602b6f7a823292a831 /commands | |
| parent | abd33f47fbbcc92610b83341c61f5d1911eed590 (diff) | |
| parent | 1881a2ecd48be772fd83b20068fe9946f1365eeb (diff) | |
| download | discordbot-develop.tar.gz discordbot-develop.zip | |
Merge branch 'master' into developdevelop
Diffstat (limited to 'commands')
| -rw-r--r-- | commands/vainsocial/about.js | 37 | ||||
| -rw-r--r-- | commands/vainsocial/guild_add.js | 52 | ||||
| -rw-r--r-- | commands/vainsocial/guild_create.js | 70 | ||||
| -rw-r--r-- | commands/vainsocial/guild_member.js | 74 | ||||
| -rw-r--r-- | commands/vainsocial/guild_pin.js | 46 | ||||
| -rw-r--r-- | commands/vainsocial/guild_rm.js | 48 | ||||
| -rw-r--r-- | commands/vainsocial/guild_role.js | 46 | ||||
| -rw-r--r-- | commands/vainsocial/guild_update.js | 60 | ||||
| -rw-r--r-- | commands/vainsocial/guild_view.js | 46 | ||||
| -rw-r--r-- | commands/vainsocial/match.js | 68 | ||||
| -rw-r--r-- | commands/vainsocial/matches.js | 56 | ||||
| -rw-r--r-- | commands/vainsocial/me.js | 47 | ||||
| -rw-r--r-- | commands/vainsocial/user.js | 59 |
13 files changed, 709 insertions, 0 deletions
diff --git a/commands/vainsocial/about.js b/commands/vainsocial/about.js new file mode 100644 index 0000000..e7941e3 --- /dev/null +++ b/commands/vainsocial/about.js @@ -0,0 +1,37 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"); + +const PREVIEW = process.env.PREVIEW != "false", + ROOTURL = (PREVIEW? "https://preview.vainsocial.com/":"https://vainsocial.com/"); + +module.exports = class ShowAboutCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "about", + group: "vainsocial", + memberName: "about", + description: "Shows invite links and developer contact details." + }); + } + async run(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 new file mode 100644 index 0000000..bf8f8f6 --- /dev/null +++ b/commands/vainsocial/guild_add.js @@ -0,0 +1,52 @@ +#!/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"), + GuildAddView = require("../../views/guild_progress"); + +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" + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-add"); + let playersStatus = {}; + const playersWaiters = args.map((name) => api.subscribeUpdates(name)), + guildAddView = new GuildAddView(msg, playersStatus); + // create waiter dict & data dict + await Promise.each(playersWaiters, async (waiter, idx) => { + let success = false; + try { + playersStatus[args[idx]] = "Loading…"; + await guildAddView.respond(); + await api.upsearchPlayerSync(args[idx]); + success = true; + } catch (err) { + console.error(err); + playersStatus[args[idx]] = err.error.err; + success = false; + } + if (success) { + await api.addToGuild(msg.author.id, args[idx]); + playersStatus[args[idx]] = "Loaded."; + } + }); + await guildAddView.respond("Your Guild members were added."); + } +}; diff --git a/commands/vainsocial/guild_create.js b/commands/vainsocial/guild_create.js new file mode 100644 index 0000000..a8caa6a --- /dev/null +++ b/commands/vainsocial/guild_create.js @@ -0,0 +1,70 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"), + api = require("../../api"), + GuildCreateView = require("../../views/guild_create"); + +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: 2, + 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"); + const guildCreateView = new GuildCreateView(msg, msg.author.id); + if (msg.guild.id != 283790513998659585) + return await guildCreateView.error(oneLine` +Guilds creation is currently running in closed beta. +If you want to participate, join our development Discord: https://discord.gg/txTchJY +`); + try { + await api.post("/guild", { + shard_id: args.region, + name: args.name, + identifier: args.tag, + user_token: msg.author.id + }); + } catch (err) { + console.error(err); + return await guildCreateView.error(err.error.err); + } + await guildCreateView.respond(); + } +}; diff --git a/commands/vainsocial/guild_member.js b/commands/vainsocial/guild_member.js new file mode 100644 index 0000000..e72fff1 --- /dev/null +++ b/commands/vainsocial/guild_member.js @@ -0,0 +1,74 @@ +#!/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"), + GuildMemberView = require("../../views/guild_member"); + +module.exports = class ViewGuildMemberCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-guildmember", + aliases: ["vguild-member", "vgm"], + group: "vainsocial-guild", + memberName: "vainsocial-guildmember", + description: "View a Guild member in detail.", + examples: ["vgm StormCallerSr"], + args: [ { + key: "name", + label: "name", + prompt: "Please specify a Guild member's name.", + type: "string", + min: 2, + default: "?" + }, { + key: "guild", + label: "guild", + prompt: "Please specify a Guild's name.", + type: "string", + min: 2, + default: "?" + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-member"); + const guildMemberView = new GuildMemberView(msg); + // get IGN or default + let ign; + try { + ign = await util.ignForUser(args.name, msg.author.id); + } catch (err) { + return await guildMemberView.error(strings.unknown(msg)); + } + // get guild: name, server default, self + let guildName = args.guild, guild; + if (guildName == "?") { + guildName = msg.guild.settings.get("default-guild-name"); + } + + try { + let members; + // TODO. + if (guildName == undefined) members = (await api.getGuild(msg.author.id)).members; + else members = await api.getGuildMembersByGuildName(guildName); + console.log(guildName); + if (members.length == 0) + throw { error: { err: "Could not find that Guild." } }; + + const member = members.filter((m) => m.player.name == args.name)[0]; + if (member == undefined) + throw { error: { err: "Player is not in the Guild." } }; + const player = await api.getPlayer(member.player.name); + const matches = await api.getMatches(player.name); + await guildMemberView.respond(member, player, matches); + } catch (err) { + console.error(err); + return await guildMemberView.error(err.error.err); + } + } +}; diff --git a/commands/vainsocial/guild_pin.js b/commands/vainsocial/guild_pin.js new file mode 100644 index 0000000..986666e --- /dev/null +++ b/commands/vainsocial/guild_pin.js @@ -0,0 +1,46 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"), + api = require("../../api"), + SimpleView = require("../../views/simple"); + +module.exports = class PinGuildCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-guildpin", + aliases: ["vguild-pin", "vgpin"], + group: "vainsocial-guild", + memberName: "vainsocial-guildpin", + description: "Share your Guild on a server.", + examples: ["vgview"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your Guild's name.", + type: "string", + min: 2, + default: "?" + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-pin"); + const pinView = new SimpleView(msg); + if (!msg.member.hasPermission('ADMINISTRATOR')) + return await pinView.error("You need to be server administrator to pin a GUild."); + let guild; + try { + guild = await api.getGuild(msg.author.id); + } catch (err) { + console.log(err); + return await guildOverviewView.error(err.error.err); + } + msg.guild.settings.set("default-guild-name", guild.name); + await pinView.respond(`Successfully pinned the Guild \`${guild.name}\` to your server.`); + } +}; diff --git a/commands/vainsocial/guild_rm.js b/commands/vainsocial/guild_rm.js new file mode 100644 index 0000000..e74aea4 --- /dev/null +++ b/commands/vainsocial/guild_rm.js @@ -0,0 +1,48 @@ +#!/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"), + GuildRmView = require("../../views/guild_progress"); + +module.exports = class AddGuildMemberCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-guildrm", + aliases: ["vguild-rm", "vgrm"], + group: "vainsocial-guild", + memberName: "vainsocial-guildrm", + description: "Remove a member from your Guild.", + details: oneLine` +Remove an IGN from your Guild. +`, + examples: ["vgrm StormCallerSr", "vgrm StormCallerSr shutterfly"], + argsType: "multiple" + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-rm"); + let playersStatus = {}; + const guildRmView = new GuildRmView(msg, playersStatus); + try { + await Promise.each(args, async (name) => { + try { + playersStatus[name] = "Removing…"; + await api.removeFromGuild(msg.author.id, name); + playersStatus[name] = "Removed."; + await guildRmView.respond(); + } catch (err) { + playersStatus[name] = err.error.err; + } + }); + } catch (err) { + console.error(err); + return await guildRmView.error(err.error.err); + } + await guildRmView.respond("Your Guild members were removed."); + } +}; diff --git a/commands/vainsocial/guild_role.js b/commands/vainsocial/guild_role.js new file mode 100644 index 0000000..50b88e4 --- /dev/null +++ b/commands/vainsocial/guild_role.js @@ -0,0 +1,46 @@ +#!/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"), + SimpleView = require("../../views/simple"); + +module.exports = class RoleGuildMemberCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-guildrole", + aliases: ["vguild-role", "vgrole", "vgr"], + group: "vainsocial-guild", + memberName: "vainsocial-guildrole", + description: "Change a Guild member's role.", + examples: ["vgrole StormCallerSr Officer", "vgrole shutterfly Leader"], + args: [ { + key: "name", + label: "name", + prompt: "Please specify a Guild member's name.", + type: "string", + min: 2 + }, { + key: "role", + label: "role", + prompt: "Please specify the member's new role.", + type: "string" + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-role"); + const simpleView = new SimpleView(msg); + try { + const member = await api.changeRole(msg.author.id, args.name, args.role); + await simpleView.respond(`Successfully changed ${args.name}'s role to ${args.role}.`); + } catch (err) { + console.log(err); + return await simpleView.error(err.error.err); + } + } +}; diff --git a/commands/vainsocial/guild_update.js b/commands/vainsocial/guild_update.js new file mode 100644 index 0000000..a61647f --- /dev/null +++ b/commands/vainsocial/guild_update.js @@ -0,0 +1,60 @@ +#!/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"), + GuildMembersProgressView = require("../../views/guild_progress"); + +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"); + // obj of ign: player + let playersStatus = {}; + // collect an array of IGNs + let names, guild; + const guildUpdateView = new GuildMembersProgressView(msg, playersStatus); + try { + guild = await api.getGuild(msg.author.id); + names = guild.members.map((m) => m.player.name); + } catch (err) { + console.log(err); + return await guildUpdateView.error(err.error.err); + } + // update all the IGNs + const playersWaiters = names.map((name) => api.subscribeUpdates(name)); + // create waiter dict & data dict + await Promise.each(playersWaiters, async (waiter, idx) => { + playersStatus[names[idx]] = "Loading…"; + await guildUpdateView.respond(); + await api.upsearchPlayerSync(names[idx]); + playersStatus[names[idx]] = "Loaded."; + await guildUpdateView.respond(); + }); + await guildUpdateView.respond("Your Guild's fame is being updated…"); + try { + await api.calculateGuild(guild.id, msg.author.id); + } catch (err) { + console.log(err); + await guildUpdateView.error(err.error.err); + } + await guildUpdateView.respond("Your Guild was updated."); + } +}; diff --git a/commands/vainsocial/guild_view.js b/commands/vainsocial/guild_view.js new file mode 100644 index 0000000..28ddad3 --- /dev/null +++ b/commands/vainsocial/guild_view.js @@ -0,0 +1,46 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"), + api = require("../../api"), + GuildOverviewView = require("../../views/guild"); + +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: 2, + default: "?" + } ] + }); + } + // show Guild details + async run(msg, args) { + util.trackAction(msg, "vainsocial-guild-view"); + const guildOverviewView = new GuildOverviewView(msg); + try { + const guild = await api.getGuild(msg.author.id); + await guildOverviewView.respond(guild); + } catch (err) { + console.log(err); + return await guildOverviewView.error(err.error.err); + } + } +}; diff --git a/commands/vainsocial/match.js b/commands/vainsocial/match.js new file mode 100644 index 0000000..3acde84 --- /dev/null +++ b/commands/vainsocial/match.js @@ -0,0 +1,68 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"), + api = require("../../api"), + strings = require("../../strings"), + MatchView = require("../../views/match"); + +module.exports = class ShowMatchCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-match", + aliases: ["vm"], + group: "vainsocial", + memberName: "vainsocial-match", + description: "Shows a user's match in detail.", + examples: ["vm shutterfly 1"], + argsType: "multiple", + argsCount: 2, + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your in game name (Case Sensitive).", + type: "string", + default: "?", + min: 3, + max: 16 + }, { + key: "number", + label: "number", + prompt: "Please specify how far you want to go back in history. Use 1 or leave out for the latest match.", + type: "integer", + default: 1, + min: 1, + max: 10 + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-match", args.name); + let ign; + try { + ign = await util.ignForUser(args.name, msg.author.id); + } catch (err) { + return await new MatchView(msg, undefined).error(strings.unknown(msg)); + } + + const matchView = new MatchView(msg); + try { + const participations = await api.getMatches(ign); + if (args.number > participations.length) + return await msg.say(strings.tooFewMatches(ign)); + // wait for BE update + const waiter = api.subscribeUpdates(ign); + await api.upsearchPlayer(ign); + + do await matchView.respond(participations[args.number-1].match_api_id); + while (await waiter.next() != undefined); + } catch (err) { + console.error(err); + return await matchView.error(err.error.err); + } + } +}; diff --git a/commands/vainsocial/matches.js b/commands/vainsocial/matches.js new file mode 100644 index 0000000..7499725 --- /dev/null +++ b/commands/vainsocial/matches.js @@ -0,0 +1,56 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + util = require("../../util"), + api = require("../../api"), + strings = require("../../strings"), + MatchesView = require("../../views/matches"); + +module.exports = class ShowMatchesCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-history", + aliases: ["vh"], + group: "vainsocial", + memberName: "vainsocial-matches", + description: "Shows a user's match history.", + examples: ["vh shutterfly"], + argsType: "single", + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your in game name (Case Sensitive).", + type: "string", + default: "?", + min: 3, + max: 16 + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-matches", args.name); + let ign; + try { + ign = await util.ignForUser(args.name, msg.author.id); + } catch (err) { + return await strings.unknown(msg); + } + + const matchesView = new MatchesView(msg, ign); + // wait for BE update + try { + const waiter = api.subscribeUpdates(ign); + await api.upsearchPlayer(ign); + + do await matchesView.respond(); + while (await waiter.next() != undefined); + } catch (err) { + console.log(err); + return await matchesView.error(err.error.err); + } + } +}; diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js new file mode 100644 index 0000000..8679a65 --- /dev/null +++ b/commands/vainsocial/me.js @@ -0,0 +1,47 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + api = require("../../api"), + util = require("../../util"), + RegisterView = require("../../views/register"); + +module.exports = class RegisterUserCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-me", + aliases: ["vme", "vgme"], + group: "vainsocial", + memberName: "vainsocial-me", + description: "Register a users's in game name.", + details: oneLine` +Store your in game name for quicker access to other commands and for Guild management. + `, + examples: ["vme shutterfly"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your in game name (Case Sensitive).", + type: "string", + min: 3, + max: 16 + } ] + }); + } + // register a Discord account at VainSocial + async run(msg, args) { + util.trackAction(msg, "vainsocial-me", args.name); + const registerView = new RegisterView(msg, args.name); + try { + await api.upsearchPlayerSync(args.name); + await api.setUser(msg.author.id, args.name); + } catch (err) { + console.log(err); + return await registerView.error(err.error.err); + } + await registerView.respond(); + } +}; diff --git a/commands/vainsocial/user.js b/commands/vainsocial/user.js new file mode 100644 index 0000000..e251ad7 --- /dev/null +++ b/commands/vainsocial/user.js @@ -0,0 +1,59 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + 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) { + super(client, { + name: "vainsocial-user", + aliases: ["v", "vu"], + group: "vainsocial", + memberName: "vainsocial-user", + description: "Shows a player\'s profile.", + details: oneLine` +Display VainSocial lifetime statistics from Vainglory + `, + examples: ["vu shutterfly"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your in game name (Case Sensitive).", + type: "string", + default: "?", + min: 3, + max: 16 + } ] + }); + } + async run(msg, args) { + util.trackAction(msg, "vainsocial-user", args.name); + let ign; + try { + ign = await util.ignForUser(args.name, msg.author.id); + } catch (err) { + return await new PlayerView(msg, args.name).error(strings.unknown(msg)); + } + + const playerView = new PlayerView(msg, ign); + try { + // wait for BE update + const waiter = api.subscribeUpdates(ign); + await api.upsearchPlayer(ign); + + do await playerView.respond(); + while (await waiter.next() != undefined); + } catch (err) { + console.log(err); + return await playerView.error(err.error.err); + } + } +}; |
