summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-26 03:41:24 -0700
committerFuwn <[email protected]>2025-09-26 03:41:24 -0700
commitf54fe78fc2d1d6e842c4626eac9a2cde32693399 (patch)
tree43ce848432c733173f0a717d247ce8ecc0f9f2e2
parentfeat(gateway:moderationAgent): Update analysis guidelines (diff)
downloadumabotdiscord-f54fe78fc2d1d6e842c4626eac9a2cde32693399.tar.xz
umabotdiscord-f54fe78fc2d1d6e842c4626eac9a2cde32693399.zip
feat(gateway:commands): Add CRP command
-rw-r--r--packages/gateway/src/commands/crp.ts99
-rw-r--r--packages/gateway/src/commands/index.ts2
2 files changed, 101 insertions, 0 deletions
diff --git a/packages/gateway/src/commands/crp.ts b/packages/gateway/src/commands/crp.ts
new file mode 100644
index 0000000..9f7c509
--- /dev/null
+++ b/packages/gateway/src/commands/crp.ts
@@ -0,0 +1,99 @@
+import { Client, Events, Message, Role } from "discord.js";
+
+export const handleCrpCommand = (client: Client) => {
+ client.on(Events.MessageCreate, async (message: Message) => {
+ if (message.author.bot) return;
+
+ if (message.content.toLowerCase().startsWith("uma!crp")) {
+ const application = await client.application?.fetch();
+ const ownerId = application?.owner?.id;
+
+ if (message.author.id !== ownerId) {
+ await message.reply("❌ Only the server owner can use this command.");
+
+ 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 sourceRoleMention = parameters[0];
+ const targetRoleMentions = parameters.slice(1);
+ let sourceRole: Role | undefined;
+
+ if (sourceRoleMention === "@everyone") {
+ sourceRole = message.guild?.roles.everyone;
+ } else {
+ const sourceRoleMatch = sourceRoleMention.match(/<@&(\d+)>/);
+
+ if (!sourceRoleMatch) {
+ await message.reply(
+ "❌ Please mention a valid source role. Example: `@everyone` or `@RoleName`",
+ );
+
+ return;
+ }
+
+ const sourceRoleId = sourceRoleMatch[1];
+
+ sourceRole = message.guild?.roles.cache.get(sourceRoleId);
+ }
+
+ if (!sourceRole) {
+ await message.reply("❌ Source role not found.");
+
+ return;
+ }
+
+ const targetRoles: Role[] = [];
+
+ for (const mention of targetRoleMentions) {
+ const targetRoleMatch = mention.match(/<@&(\d+)>/);
+
+ 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);
+ }
+
+ try {
+ const sourcePermissions = sourceRole.permissions.toArray();
+
+ for (const targetRole of targetRoles)
+ await targetRole.setPermissions(sourcePermissions);
+
+ 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.",
+ );
+ }
+ }
+ });
+};
diff --git a/packages/gateway/src/commands/index.ts b/packages/gateway/src/commands/index.ts
index c94db00..29e3f71 100644
--- a/packages/gateway/src/commands/index.ts
+++ b/packages/gateway/src/commands/index.ts
@@ -1,8 +1,10 @@
import { Client } from "discord.js";
import { handleSayCommand } from "./say";
import { handleStartCommand } from "./start";
+import { handleCrpCommand } from "./crp";
export const handleCommands = (client: Client) => {
handleSayCommand(client);
handleStartCommand(client);
+ handleCrpCommand(client);
};