This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add roleinfo command (#394)
* Initial roleinfo progress * Extract roles per page into variable * Roleinfo changes * Some more changes half a year later * Something changed that I have to commit now to mess with git * Finishing touches * You won't belive what this commit does! * This commit will blow your socks off!
- Loading branch information
1 parent
13d76fe
commit 8d590de
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const moment = require("moment"); | ||
const PaginatedEmbed = require("../../Modules/MessageUtils/PaginatedEmbed"); | ||
const Permissions = require("discord.js/src/util/Permissions.js"); | ||
|
||
const rolesPerPage = 25; | ||
|
||
module.exports = async ({ client, Constants: { Colors, Text }, Utils: { TitlecasePermissions } }, documents, msg, commandData) => { | ||
if (!msg.suffix) { | ||
const guildRoles = [...msg.guild.roles.values()].sort((a, b) => b.position - a.position); | ||
const descriptions = []; | ||
for (let i = 0; i < guildRoles.length; i += rolesPerPage) { | ||
const roleSegment = guildRoles.slice(i, i + rolesPerPage).join("\n"); | ||
descriptions.push(`These are the roles on this server:\n\n${i ? `...${i} previous roles\n` : ""}${roleSegment}${i + rolesPerPage < guildRoles.length ? `\n...and ${guildRoles.length - i - rolesPerPage} more` : ""}`); | ||
} | ||
|
||
const memberRoles = [...msg.member.roles.values()].sort((a, b) => b.position - a.position); | ||
const totalPermissionsBitfield = memberRoles.reduce((a, b) => a | b.permissions, 0); // eslint-disable-line no-bitwise | ||
const totalPermissions = new Permissions(totalPermissionsBitfield); | ||
for (let i = 0; i < memberRoles.length; i += rolesPerPage) { | ||
const roleSegment = memberRoles.slice(i, i + rolesPerPage).join("\n"); | ||
descriptions.push([ | ||
`You currently have those roles:\n\n${i ? `...${i} previous roles\n` : ""}${roleSegment}${i + rolesPerPage < memberRoles.length ? `\n...and ${memberRoles.length - i - rolesPerPage} more` : ""}`, | ||
"\nYour roles grant you get the following permissions:", | ||
totalPermissionsBitfield ? `\`\`\`${TitlecasePermissions(totalPermissions.toArray(false).join(", "))}\`\`\`` : "You do not have any permissions on this server βοΈ", | ||
totalPermissions.has(Permissions.FLAGS.ADMINISTRATOR, false) ? "β οΈ You have Administrator permissions which bypasses any other permission or override" : "", | ||
].join("\n")); | ||
} | ||
if (descriptions.length === 2 && descriptions[0].length + descriptions[1].length < 2048) { | ||
return msg.send({ | ||
embed: { | ||
color: Colors.INFO, | ||
title: `This guild has ${guildRoles.length} roles`, | ||
description: `${descriptions[0]}\n\n${descriptions[1]}`, | ||
}, | ||
}); | ||
} | ||
|
||
await new PaginatedEmbed(msg, { | ||
color: Colors.INFO, | ||
title: `This guild has ${guildRoles.length} roles`, | ||
description: `{description}`, | ||
footer: `Page {currentPage} out of {totalPages}`, | ||
}, { | ||
descriptions, | ||
}).init(); | ||
} else { | ||
let role; | ||
try { | ||
role = await client.roleSearch(msg.suffix, msg.guild); | ||
} catch (err) { | ||
if (err.code === "FAILED_TO_FIND") { | ||
return msg.send({ | ||
embed: { | ||
color: Colors.SOFT_ERR, | ||
title: "What's that role? π·οΈ", | ||
description: "I do not know anything about a role with that name.", | ||
footer: { | ||
text: "You can find a list of all roles by running this command without any arguments.", | ||
}, | ||
}, | ||
}); | ||
} | ||
throw err; | ||
} | ||
const permissions = role.permissions.toArray(false).join(", "); | ||
const elements = [ | ||
`π¨ Color: **${role.color ? role.hexColor.toUpperCase() : "None"}**`, | ||
`π₯ Members: **${role.members.size}**`, | ||
`#β£ Position: **${msg.guild.roles.size - role.position}**`, | ||
`π Created: **${moment(role.createdTimestamp).fromNow()}**`, | ||
]; | ||
if (role.mentionable) { | ||
elements.push("π’ Mentionable by everyone"); | ||
} | ||
if (role.hoist) { | ||
elements.push("π Hoisted in member list"); | ||
} | ||
if (role.managed) { | ||
elements.push("π€ Managed by an integration"); | ||
} | ||
elements.push(`β Permissions:${permissions.length ? `\n\`\`\`${TitlecasePermissions(permissions)}\`\`\`` : " This role does not grant any additional permissions"}`); | ||
if (role.permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) { | ||
elements.push("β οΈ This role grants Administrator permissions which bypasses any other permission or override"); | ||
} | ||
return msg.send({ | ||
embed: { | ||
title: `Information about role ${role.name} :: ${role.id}`, | ||
color: role.color || null, | ||
description: elements.join("\n"), | ||
}, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = str => str.replace(/\w+(_\w+)*/g, match => match.split("_").map(v => `${v.charAt(0)}${v.substr(1).toLowerCase()}`).join(" ")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters