3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Merge pull request #307 from almeidx/role-info-perms

fix permissions not showing properly in roleinfo
This commit is contained in:
Miikka 2022-04-21 22:29:01 +03:00 committed by GitHub
commit 63fa5bc533
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 9 deletions

View file

@ -1,8 +1,9 @@
import { MessageEmbedOptions, Role } from "discord.js"; import { MessageEmbedOptions, Permissions, Role } from "discord.js";
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import moment from "moment-timezone"; import moment from "moment-timezone";
import { EmbedWith, preEmbedPadding, trimLines } from "../../../utils"; import { EmbedWith, preEmbedPadding, trimLines } from "../../../utils";
import { PERMISSION_NAMES } from "../../../utils/permissionNames.js";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { UtilityPluginType } from "../types"; import { UtilityPluginType } from "../types";
@ -35,14 +36,9 @@ export async function getRoleInfoEmbed(
round: true, round: true,
}); });
const rolePerms = Object.keys(role.permissions.toJSON()).map((p) => const rolePerms = role.permissions.has(Permissions.FLAGS.ADMINISTRATOR)
p ? [PERMISSION_NAMES.ADMINISTRATOR]
// Voice channel related permission names start with 'voice' : role.permissions.toArray().map((p) => PERMISSION_NAMES[p]);
.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 // -1 because of the @everyone role
const totalGuildRoles = pluginData.guild.roles.cache.size - 1; const totalGuildRoles = pluginData.guild.roles.cache.size - 1;

View file

@ -0,0 +1,46 @@
import { PermissionFlags } from "discord.js";
import { EMPTY_CHAR } from "../utils";
export const PERMISSION_NAMES: Record<keyof PermissionFlags, string> = {
ADD_REACTIONS: "Add Reactions",
ADMINISTRATOR: "Administrator",
ATTACH_FILES: "Attach Files",
BAN_MEMBERS: "Ban Members",
CHANGE_NICKNAME: "Change Nickname",
CONNECT: "Connect",
CREATE_INSTANT_INVITE: "Create Invite",
CREATE_PRIVATE_THREADS: "Create Private Threads",
CREATE_PUBLIC_THREADS: "Create Public Threads",
DEAFEN_MEMBERS: "Deafen Members",
EMBED_LINKS: "Embed Links",
KICK_MEMBERS: "Kick Members",
MANAGE_CHANNELS: "Manage Channels",
MANAGE_EMOJIS_AND_STICKERS: "Manage Emojis and Stickers",
MANAGE_GUILD: "Manage Server",
MANAGE_MESSAGES: "Manage Messages",
MANAGE_NICKNAMES: "Manage Nicknames",
MANAGE_ROLES: "Manage Roles",
MANAGE_THREADS: "Manage Threads",
MANAGE_WEBHOOKS: "Manage Webhooks",
MENTION_EVERYONE: `Mention @${EMPTY_CHAR}everyone, @${EMPTY_CHAR}here, and All Roles`,
MOVE_MEMBERS: "Move Members",
MUTE_MEMBERS: "Mute Members",
PRIORITY_SPEAKER: "Priority Speaker",
READ_MESSAGE_HISTORY: "Read Message History",
REQUEST_TO_SPEAK: "Request to Speak",
SEND_MESSAGES: "Send Messages",
SEND_MESSAGES_IN_THREADS: "Send Messages in Threads",
SEND_TTS_MESSAGES: "Send Text-To-Speech Messages",
SPEAK: "Speak",
START_EMBEDDED_ACTIVITIES: "Start Embedded Activities",
STREAM: "Video",
USE_APPLICATION_COMMANDS: "Use Application Commands",
USE_EXTERNAL_EMOJIS: "Use External Emoji",
USE_EXTERNAL_STICKERS: "Use External Stickers",
USE_PRIVATE_THREADS: "Use Private Threads",
USE_PUBLIC_THREADS: "Use Public Threads",
USE_VAD: "Use Voice Activity",
VIEW_AUDIT_LOG: "View Audit Log",
VIEW_CHANNEL: "View Channels",
VIEW_GUILD_INSIGHTS: "View Guild Insights",
};