diff options
| author | Fuwn <[email protected]> | 2025-09-28 00:06:49 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-28 00:06:49 -0700 |
| commit | 956ed319e7722d168b4c23d5c6aeb85b20e5b15d (patch) | |
| tree | df2ec3a95d405d0d6c6ebcc93f7de1e2e9f4484d /packages/gateway/src/commands/crp.ts | |
| parent | refactor(gateway): Consolidate event handlers (diff) | |
| download | umabotdiscord-956ed319e7722d168b4c23d5c6aeb85b20e5b15d.tar.xz umabotdiscord-956ed319e7722d168b4c23d5c6aeb85b20e5b15d.zip | |
fix(gateway): Lint
Diffstat (limited to 'packages/gateway/src/commands/crp.ts')
| -rw-r--r-- | packages/gateway/src/commands/crp.ts | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/packages/gateway/src/commands/crp.ts b/packages/gateway/src/commands/crp.ts index 8503cb3..4758574 100644 --- a/packages/gateway/src/commands/crp.ts +++ b/packages/gateway/src/commands/crp.ts @@ -1,97 +1,97 @@ import { Message, Role } from "discord.js"; export const handleCrpCommand = async (message: Message) => { - if (message.author.bot) return; + if (message.author.bot) return; - if (message.content.toLowerCase().startsWith("uma!crp")) { - const application = await message.client.application?.fetch(); - const ownerId = application?.owner?.id; + if (message.content.toLowerCase().startsWith("uma!crp")) { + const application = await message.client.application?.fetch(); + const ownerId = application?.owner?.id; - if (message.author.id !== ownerId) { - await message.reply("❌ Only the server owner can use this command."); + if (message.author.id !== ownerId) { + await message.reply("❌ Only the server owner can use this command."); - return; - } + return; + } + + const parameters = message.content.split(" ").slice(1); + + if (parameters.length < 2) { + await message.reply( + "❌ Usage: `uma!crp <source_role_mention> <target_role_mention1> [target_role_mention2] ...`\nExample: `uma!crp @everyone @test1 @test2 @test3`", + ); + + return; + } - const parameters = message.content.split(" ").slice(1); + const sourceRoleMention = parameters[0]; + const targetRoleMentions = parameters.slice(1); + let sourceRole: Role | undefined; - if (parameters.length < 2) { + if (sourceRoleMention === "@everyone") { + sourceRole = message.guild?.roles.everyone; + } else { + const sourceRoleMatch = sourceRoleMention.match(/<@&(\d+)>/); + + if (!sourceRoleMatch) { await message.reply( - "❌ Usage: `uma!crp <source_role_mention> <target_role_mention1> [target_role_mention2] ...`\nExample: `uma!crp @everyone @test1 @test2 @test3`", + "❌ Please mention a valid source role. Example: `@everyone` or `@RoleName`", ); return; } - const sourceRoleMention = parameters[0]; - const targetRoleMentions = parameters.slice(1); - let sourceRole: Role | undefined; + const sourceRoleId = sourceRoleMatch[1]; - if (sourceRoleMention === "@everyone") { - sourceRole = message.guild?.roles.everyone; - } else { - const sourceRoleMatch = sourceRoleMention.match(/<@&(\d+)>/); + sourceRole = message.guild?.roles.cache.get(sourceRoleId); + } - if (!sourceRoleMatch) { - await message.reply( - "❌ Please mention a valid source role. Example: `@everyone` or `@RoleName`", - ); + if (!sourceRole) { + await message.reply("❌ Source role not found."); - return; - } + return; + } - const sourceRoleId = sourceRoleMatch[1]; + const targetRoles: Role[] = []; - sourceRole = message.guild?.roles.cache.get(sourceRoleId); - } + for (const mention of targetRoleMentions) { + const targetRoleMatch = mention.match(/<@&(\d+)>/); - if (!sourceRole) { - await message.reply("❌ Source role not found."); + if (!targetRoleMatch) { + await message.reply( + `❌ Invalid role mention: ${mention}. Please mention valid roles.`, + ); return; } - const targetRoles: Role[] = []; + const targetRoleId = targetRoleMatch[1]; + const targetRole = message.guild?.roles.cache.get(targetRoleId); - for (const mention of targetRoleMentions) { - const targetRoleMatch = mention.match(/<@&(\d+)>/); + if (!targetRole) { + await message.reply(`❌ Target role not found: ${mention}`); - if (!targetRoleMatch) { - await message.reply( - `❌ Invalid role mention: ${mention}. Please mention valid roles.`, - ); - - return; - } - - const targetRoleId = targetRoleMatch[1]; - const targetRole = message.guild?.roles.cache.get(targetRoleId); - - if (!targetRole) { - await message.reply(`❌ Target role not found: ${mention}`); - - return; - } - - targetRoles.push(targetRole); + return; } - try { - const sourcePermissions = sourceRole.permissions.toArray(); + targetRoles.push(targetRole); + } - for (const targetRole of targetRoles) - await targetRole.setPermissions(sourcePermissions); + try { + const sourcePermissions = sourceRole.permissions.toArray(); - const targetRoleNames = targetRoles.map((role) => role.name).join(", "); + for (const targetRole of targetRoles) + await targetRole.setPermissions(sourcePermissions); - await message.reply( - `✅ Successfully copied permissions from **${sourceRole.name}** to: **${targetRoleNames}**`, - ); - } catch (error) { - console.error("Error copying role permissions:", error); - await message.reply( - "❌ Failed to copy role permissions. Check bot permissions and try again.", - ); - } + const targetRoleNames = targetRoles.map((role) => role.name).join(", "); + + await message.reply( + `✅ Successfully copied permissions from **${sourceRole.name}** to: **${targetRoleNames}**`, + ); + } catch (error) { + console.error("Error copying role permissions:", error); + await message.reply( + "❌ Failed to copy role permissions. Check bot permissions and try again.", + ); } + } }; |