3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-20 16:25:03 +00:00

improvements for the RoleInfoCmd

- Made the role paramter required
- Added the total amount of roles to the position field in the embed
- Fixed markdown issues when a role didn't have any permissions
This commit is contained in:
Almeida 2021-05-05 02:32:15 +01:00
parent ab569e7c92
commit 58542e0169
2 changed files with 14 additions and 19 deletions

View file

@ -10,17 +10,11 @@ export const RoleInfoCmd = utilityCmd({
permission: "can_roleinfo",
signature: {
role: ct.role({ required: false }),
role: ct.role({ required: true }),
},
async run({ message, args, pluginData }) {
if (!args.role) {
sendErrorMessage(pluginData, message.channel, "Role not found");
return;
}
const embed = await getRoleInfoEmbed(pluginData, args.role, message.author.id);
message.channel.createMessage({ embed });
},
});

View file

@ -35,16 +35,17 @@ export async function getRoleInfoEmbed(
round: true,
});
const rolePerms = Object.keys(role.permissions.json)
.map(p =>
p
// Voice channel related permission names start with 'voice'
.replace(/^voice/i, "")
.replace(/([a-z])([A-Z])/g, "$1 $2")
.toLowerCase()
.replace(/(^\w{1})|(\s{1}\w{1})/g, l => l.toUpperCase()),
)
.join(", ");
const rolePerms = Object.keys(role.permissions.json).map(p =>
p
// Voice channel related permission names start with 'voice'
.replace(/^voice/i, "")
.replace(/([a-z])([A-Z])/g, "$1 $2")
.toLowerCase()
.replace(/(^\w{1})|(\s{1}\w{1})/g, l => l.toUpperCase()),
);
// -1 because of the @everyone role
const totalGuildRoles = pluginData.guild.roles.size - 1;
embed.fields.push({
name: preEmbedPadding + "Role information",
@ -52,14 +53,14 @@ export async function getRoleInfoEmbed(
Name: **${role.name}**
ID: \`${role.id}\`
Created: **${roleAge} ago** (\`${prettyCreatedAt}\`)
Position: **${role.position}**
Position: **${role.position} / ${totalGuildRoles}**
Color: **#${role.color
.toString(16)
.toUpperCase()
.padStart(6, "0")}**
Mentionable: **${role.mentionable ? "Yes" : "No"}**
Hoisted: **${role.hoist ? "Yes" : "No"}**
Permissions: \`${rolePerms}\`
Permissions: \`${rolePerms.length ? rolePerms.join(", ") : "None"}\`
Mention: <@&${role.id}> (\`<@&${role.id}>\`)
`),
});