This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 185
Add roleinfo command #394
Merged
Gilbert142
merged 8 commits into
GAwesomeBot:indev-4.0.2
from
wasdennnoch:new-commands-roleinfo
Dec 4, 2018
Merged
Add roleinfo command #394
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
82e6ef7
Initial roleinfo progress
wasdennnoch 42f1c91
Extract roles per page into variable
wasdennnoch 33e24a2
Roleinfo changes
wasdennnoch 3d6e052
Some more changes half a year later
wasdennnoch 5c6683c
Something changed that I have to commit now to mess with git
wasdennnoch e721ca3
Finishing touches
wasdennnoch 1199318
You won't belive what this commit does!
wasdennnoch 72396ab
This commit will blow your socks off!
wasdennnoch File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; | ||
Gilbert142 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Single new-line might be too crowded. Consider using two instead? |
||
}, | ||
}); | ||
} | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title is inconsistent with title of non-paged message. (Missing ":")