3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 00:35:02 +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", permission: "can_roleinfo",
signature: { signature: {
role: ct.role({ required: false }), role: ct.role({ required: true }),
}, },
async run({ message, args, pluginData }) { 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); const embed = await getRoleInfoEmbed(pluginData, args.role, message.author.id);
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
}, },
}); });

View file

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