From 4339ae0134ec5fee4db7178de08c6e0638232d15 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 24 Jul 2017 16:47:26 +0000 Subject: [PATCH] Role Info, Permissions Stuff --- assets/json/permissions.json | 30 +++++++++++++++++++ commands/guild-info/role-info.js | 50 ++++++++++++++++++++++++++++++++ package.json | 2 +- structures/Command.js | 5 ++-- structures/Util.js | 5 ++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 assets/json/permissions.json create mode 100644 commands/guild-info/role-info.js diff --git a/assets/json/permissions.json b/assets/json/permissions.json new file mode 100644 index 00000000..d6408253 --- /dev/null +++ b/assets/json/permissions.json @@ -0,0 +1,30 @@ +{ + "CREATE_INSTANT_INVITE": "Create Instant Invite", + "KICK_MEMBERS": "Kick Members", + "BAN_MEMBERS": "Ban Members", + "ADMINISTRATOR": "Administrator", + "MANAGE_CHANNELS": "Manage Channels", + "MANAGE_GUILD": "Manage Server", + "ADD_REACTIONS": "Add Reactions", + "VIEW_AUDIT_LOG": "View Audit Log", + "READ_MESSAGES": "Read Messages", + "SEND_MESSAGES": "Send Messages", + "SEND_TTS_MESSAGES": "Send TTS Messages", + "MANAGE_MESSAGES": "Manage Messages", + "EMBED_LINKS": "Embed Links", + "ATTACH_FILES": "Attach Files", + "READ_MESSAGE_HISTORY": "Read Message History", + "MENTION_EVERYONE": "Mention Everyone", + "USE_EXTERNAL_EMOJIS": "Use External Emojis", + "CONNECT": "Connect", + "SPEAK": "Speak", + "MUTE_MEMBERS": "Mute Members", + "DEAFEN_MEMBERS": "Deafen Members", + "MOVE_MEMBERS": "Move Members", + "USE_VAD": "Use Voice Activity", + "CHANGE_NICKNAME": "Change Nickname", + "MANAGE_NICKNAMES": "Manage Nicknames", + "MANAGE_ROLES": "Manage Roles", + "MANAGE_WEBHOOKS": "Manage Webhooks", + "MANAGE_EMOJIS": "Manage Emojis" +} diff --git a/commands/guild-info/role-info.js b/commands/guild-info/role-info.js new file mode 100644 index 00000000..241b0f15 --- /dev/null +++ b/commands/guild-info/role-info.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const moment = require('moment'); +const perms = require('../../assets/json/permissions'); +const { placeholder } = require('../../structures/Util'); + +module.exports = class RoleInfoCommand extends Command { + constructor(client) { + super(client, { + name: 'role-info', + aliases: ['role'], + group: 'guild-info', + memberName: 'role-info', + description: 'Responds with detailed information on a role.', + guildOnly: true, + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'role', + prompt: 'Which role would you like to get info on?', + type: 'role' + } + ] + }); + } + + run(msg, args) { + const { role } = args; + const embed = new MessageEmbed() + .setColor(role.hexColor) + .setThumbnail(placeholder({ color: role.hexColor.replace('#', '') })) + .addField('❯ Name', + role.name, true) + .addField('❯ ID', + role.id, true) + .addField('❯ Creation Date', + moment(role.createdAt).format('MMMM Do YYYY'), true) + .addField('❯ Color', + role.hexColor.toUpperCase(), true) + .addField('❯ Hoisted', + role.hoist ? 'Yes' : 'No', true) + .addField('❯ Mentionable', + role.mentionable ? 'Yes' : 'No', true) + .addField('❯ Position', + msg.guild.roles.size - role.calculatedPosition, true) + .addField('❯ Permissions', + Object.keys(role.serialize()).filter((perm) => role.serialize()[perm]).map((perm) => perms[perm])); + return msg.embed(embed); + } +}; diff --git a/package.json b/package.json index 2f07734a..d70ae0cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.5.0", + "version": "27.6.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Command.js b/structures/Command.js index c2e18049..d0b57e30 100644 --- a/structures/Command.js +++ b/structures/Command.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const perms = require('../assets/json/permissions'); class XiaoCommand extends Command { constructor(client, info) { @@ -25,14 +26,14 @@ class XiaoCommand extends Command { if (this.clientPermissions) { for (const permission of this.clientPermissions) { if (!msg.channel.permissionsFor(this.client.user).has(permission)) { - return `This Command requires the \`${permission}\` Permission.`; + return `This Command requires the \`${perms[permission]}\` Permission.`; } } } if (this.userPermissions) { for (const permission of this.userPermissions) { if (!msg.channel.permissionsFor(msg.author).has(permission)) { - return `You do not have the \`${permission}\` Permission.`; + return `You do not have the \`${perms[permission]}\` Permission.`; } } } diff --git a/structures/Util.js b/structures/Util.js index ed4e1ae1..cca5c255 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -11,6 +11,11 @@ class Util { .replace(/(&)/g, '&') .replace(/(\[i\]|\[\/i\])/g, '*'); } + + static placeholder({ size, color }) { + if (!size) size = '200x200'; + return `http://via.placeholder.com/${size}/${color}/${color}`; + } static dBots(count, id) { snekfetch .post(`https://bots.discord.pw/api/bots/${id}/stats`)