Skip to content

Commit

Permalink
getPermissionName --> getEnumName
Browse files Browse the repository at this point in the history
  • Loading branch information
Glazelf committed Feb 19, 2025
1 parent d8bff2e commit 80bddd5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions commands/mod/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
import sendMessage from "../../util/discord/sendMessage.js";
import isAdmin from "../../util/discord/perms/isAdmin.js";
import getTime from "../../util/getTime.js";
import getPermissionName from "../../util/discord/getPermissionName.js";
import getEnumName from "../../util/discord/getEnumName.js";
import formatName from "../../util/discord/formatName.js";
import globalVars from "../../objects/globalVars.json" with { type: "json" };

const requiredPermission = PermissionFlagsBits.BanMembers;
const requiredPermissionName = getPermissionName(requiredPermission);
const requiredPermissionName = getEnumName(requiredPermission, PermissionFlagsBits);

export default async (interaction, messageFlags) => {
let adminBool = isAdmin(interaction.member);
Expand Down Expand Up @@ -56,7 +56,7 @@ export default async (interaction, messageFlags) => {
let userRole = interaction.member.roles.highest;
let targetRole = member.roles.highest;
let botRole = interaction.guild.members.me.roles.highest;
if (member.id == interaction.guild.ownerId) return sendMessage({interaction: interaction, content: `I can not ban ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.`});
if (member.id == interaction.guild.ownerId) return sendMessage({ interaction: interaction, content: `I can not ban ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.` });
if (targetRole.position >= userRole.position) return sendMessage({ interaction: interaction, content: `You can not ban ${usernameFormatted} (${member.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to yours (${formatName(userRole.name)}).` });
if (targetRole.position >= botRole.position) return sendMessage({ interaction: interaction, content: `I can not ban ${usernameFormatted} (${user.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to mine (${formatName(botRole.name)}).` });
if (!member.bannable) return sendMessage({ interaction: interaction, content: banFailString });
Expand Down
6 changes: 3 additions & 3 deletions commands/mod/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
import sendMessage from "../../util/discord/sendMessage.js";
import isAdmin from "../../util/discord/perms/isAdmin.js";
import getTime from "../../util/getTime.js";
import getPermissionName from "../../util/discord/getPermissionName.js";
import getEnumName from "../../util/discord/getEnumName.js";
import formatName from "../../util/discord/formatName.js";
import globalVars from "../../objects/globalVars.json" with { type: "json" };

const requiredPermission = PermissionFlagsBits.KickMembers;
const requiredPermissionName = getPermissionName(requiredPermission);
const requiredPermissionName = getEnumName(requiredPermission, PermissionFlagsBits);

export default async (interaction, messageFlags) => {
let adminBool = isAdmin(interaction.member);
Expand All @@ -36,7 +36,7 @@ export default async (interaction, messageFlags) => {
let userRole = interaction.member.roles.highest;
let targetRole = member.roles.highest;
let botRole = interaction.guild.members.me.roles.highest;
if (member.id == interaction.guild.ownerId) return sendMessage({interaction: interaction, content: `I can not kick ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.`});
if (member.id == interaction.guild.ownerId) return sendMessage({ interaction: interaction, content: `I can not kick ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.` });
if (targetRole.position >= userRole.position) return sendMessage({ interaction: interaction, content: `You can not kick ${usernameFormatted} (${user.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to yours (${formatName(userRole.name)}).` });
if (targetRole.position >= botRole.position) return sendMessage({ interaction: interaction, content: `I can not kick ${usernameFormatted} (${user.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to mine (${formatName(botRole.name)}).` });
if (!member.kickable) return sendMessage({ interaction: interaction, content: kickFailString });
Expand Down
7 changes: 4 additions & 3 deletions commands/mod/mute.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import {
import sendMessage from "../../util/discord/sendMessage.js";
import isAdmin from "../../util/discord/perms/isAdmin.js";
import getTime from "../../util/getTime.js";
import getPermissionName from "../../util/discord/getPermissionName.js";
import getEnumName from "../../util/discord/getEnumName.js";
import formatName from "../../util/discord/formatName.js";
import globalVars from "../../objects/globalVars.json" with { type: "json" };

const requiredPermission = PermissionFlagsBits.ModerateMembers;
const requiredPermissionName = getPermissionName(requiredPermission);
const requiredPermissionName = getEnumName(requiredPermission, PermissionFlagsBits);
console.log(requiredPermissionName)
const maxMuteTime = 2_419_200_000; // Max time is 28 days, but we count in milliseconds

export default async (interaction, messageFlags) => {
Expand Down Expand Up @@ -54,7 +55,7 @@ export default async (interaction, messageFlags) => {
let targetRole = member.roles.highest;
let botRole = interaction.guild.members.me.roles.highest;
let usernameFormatted = formatName(user.username);
if (member.id == interaction.guild.ownerId) return sendMessage({interaction: interaction, content: `I can not mute ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.`});
if (member.id == interaction.guild.ownerId) return sendMessage({ interaction: interaction, content: `I can not mute ${usernameFormatted} (${member.id}) because they are the owner of ${formatName(interaction.guild.name)}.` });
if (targetRole.position >= userRole.position) return sendMessage({ interaction: interaction, content: `You can not mute ${usernameFormatted} (${member.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to yours (${formatName(userRole.name)}).` });
if (targetRole.position >= botRole.position) return sendMessage({ interaction: interaction, content: `I can not mute ${usernameFormatted} (${member.id}) because their highest role (${formatName(targetRole.name)}) is higher than or equal to mine (${formatName(botRole.name)}).` });
if (!member.moderatable) return sendMessage({ interaction: interaction, content: `I can not mute this user. This might be because I lack the ${inlineCode(requiredPermissionName)} permission.` });
Expand Down
4 changes: 2 additions & 2 deletions commands/mod/purge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
} from "discord.js";
import sendMessage from "../../util/discord/sendMessage.js";
import isAdmin from "../../util/discord/perms/isAdmin.js";
import getPermissionName from "../../util/discord/getPermissionName.js";
import getEnumName from "../../util/discord/getEnumName.js";
import formatName from "../../util/discord/formatName.js";
import globalVars from "../../objects/globalVars.json" with { type: "json" };

const requiredPermission = PermissionFlagsBits.ManageMessages;
const requiredPermissionName = getPermissionName(requiredPermission);
const requiredPermissionName = getEnumName(requiredPermission, PermissionFlagsBits);
const filterOldMessages = true;

export default async (interaction, messageFlags) => {
Expand Down
6 changes: 6 additions & 0 deletions util/discord/getEnumName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default (input, enum1) => { // Can't name this "enum" outside of TypeScript files, rename this in #1019
for (const e of Object.keys(enum1)) {
if (enum1[e] === input) return e;
};
return null;
};
8 changes: 0 additions & 8 deletions util/discord/getPermissionName.js

This file was deleted.

0 comments on commit 80bddd5

Please sign in to comment.