summaryrefslogtreecommitdiff
path: root/commands/vainsocial/guild_view.js
blob: c4595902f4644ff0a054da3cb60fbd5d4af23be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
    }
};