summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-11 20:08:25 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-11 20:08:25 +0200
commit01a0f341cd19247c9b3d47bf62edefcb0c1545bc (patch)
treef3f2f3a10989bac90b78f5e915e62800c49c7e38
parent3a857d9795d467fcb91910feb23e12ac3c18393c (diff)
downloaddiscordbot-01a0f341cd19247c9b3d47bf62edefcb0c1545bc.tar.gz
discordbot-01a0f341cd19247c9b3d47bf62edefcb0c1545bc.zip
guild view: sort by fame, show role; add guild role cmd
-rw-r--r--api.js20
-rw-r--r--commands/vainsocial/guild_rm.js2
-rw-r--r--commands/vainsocial/guild_role.js47
-rw-r--r--views/guild.js4
-rw-r--r--views/simple.js24
5 files changed, 94 insertions, 3 deletions
diff --git a/api.js b/api.js
index eddac54..7f0c35d 100644
--- a/api.js
+++ b/api.js
@@ -71,6 +71,16 @@ module.exports.deleteFE = module.exports.delete = async (url, params={}, cacheke
});
}
+// send a PUT and optionally bust cache
+module.exports.putFE = module.exports.put = async (url, params={}, cachekey=undefined) => {
+ if (cachekey) cache.del(cachekey);
+ return await request.put(API_FE_URL + url, {
+ form: params,
+ json: true,
+ forever: true
+ });
+}
+
module.exports.postBE = module.exports.backend = async (url) => {
return await request.post({
uri: API_BE_URL + url,
@@ -225,6 +235,16 @@ module.exports.removeFromGuild = async (token, member) => {
return membership;
}
+// change a role
+module.exports.changeRole = async (token, member, role) => {
+ const membership = await api.putFE("/guild/members/updateRole", {
+ user_token: token,
+ member_name: member,
+ new_role: role
+ }, "guild+" + token);
+ return membership;
+}
+
// recalc fame, block until timeout or points update
module.exports.calculateGuild = async (id, token) => {
const channel = new Channel(),
diff --git a/commands/vainsocial/guild_rm.js b/commands/vainsocial/guild_rm.js
index 4857c44..e74aea4 100644
--- a/commands/vainsocial/guild_rm.js
+++ b/commands/vainsocial/guild_rm.js
@@ -13,7 +13,7 @@ module.exports = class AddGuildMemberCommand extends Commando.Command {
constructor(client) {
super(client, {
name: "vainsocial-guildrm",
- aliases: ["vguild-rm", "vgrm", "vgr"],
+ aliases: ["vguild-rm", "vgrm"],
group: "vainsocial-guild",
memberName: "vainsocial-guildrm",
description: "Remove a member from your Guild.",
diff --git a/commands/vainsocial/guild_role.js b/commands/vainsocial/guild_role.js
new file mode 100644
index 0000000..b37bb79
--- /dev/null
+++ b/commands/vainsocial/guild_role.js
@@ -0,0 +1,47 @@
+#!/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,
+ default: "?"
+ }, {
+ 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/views/guild.js b/views/guild.js
index 23c2afe..6a8658b 100644
--- a/views/guild.js
+++ b/views/guild.js
@@ -14,9 +14,9 @@ const GuildOverviewView = module.exports;
module.exports = class extends View {
async text(members) {
// TODO remove when API supports order by fame
- members = members.sort((m1, m2) => m1.fame < m2.fame);
+ members.sort((m1, m2) => m1.fame < m2.fame);
return members.map((member) =>
- `${member.player.name} ${member.fame}`).join("\n");
+ `${member.player.name} *${member.status}* ${member.fame}`).join("\n");
}
async embed(guild) {
diff --git a/views/simple.js b/views/simple.js
new file mode 100644
index 0000000..5e8701a
--- /dev/null
+++ b/views/simple.js
@@ -0,0 +1,24 @@
+#!/usr/bin/node
+/* jshint esnext:true */
+"use strict";
+
+const View = require("./view"),
+ util = require("../util"),
+ api = require("../api"),
+ strings = require("../strings"),
+ oneLine = require("common-tags").oneLine;
+
+const SimpleView = module.exports;
+
+// just respond with a text
+module.exports = class extends View {
+ async text(txt) {
+ return txt;
+ }
+
+ async respond(text) {
+ this.response = await util.respond(this.msg,
+ await this.text(text), this.response);
+ return this.response;
+ }
+}