summaryrefslogtreecommitdiff
path: root/packages/gateway/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gateway/src/commands')
-rw-r--r--packages/gateway/src/commands/crp.ts128
-rw-r--r--packages/gateway/src/commands/react.ts45
-rw-r--r--packages/gateway/src/commands/say.ts176
-rw-r--r--packages/gateway/src/commands/start.ts114
-rw-r--r--packages/gateway/src/commands/utilities.ts1
5 files changed, 230 insertions, 234 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.",
+ );
}
+ }
};
diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts
index 639dec6..d8a8021 100644
--- a/packages/gateway/src/commands/react.ts
+++ b/packages/gateway/src/commands/react.ts
@@ -1,37 +1,36 @@
import { Message } from "discord.js";
export const handleReactCommand = async (message: Message) => {
- if (message.author.bot) return;
+ if (message.author.bot) return;
- if (!message.content.startsWith("uma!react")) return;
+ if (!message.content.startsWith("uma!react")) return;
- if (!message.guild || message.author.id !== message.guild.ownerId)
- return;
+ if (!message.guild || message.author.id !== message.guild.ownerId) return;
- const parameters = message.content.split(" ");
-
- if (parameters.length < 3) {
- await message.reply("Usage: `uma!react <message_id> <emoji>`");
+ const parameters = message.content.split(" ");
- return;
- }
+ if (parameters.length < 3) {
+ await message.reply("Usage: `uma!react <message_id> <emoji>`");
- const messageId = parameters[1];
- const emoji = parameters[2];
+ return;
+ }
- try {
- const targetMessage = await message.channel.messages.fetch(messageId);
-
- if (!targetMessage) {
- await message.reply("Message not found.");
+ const messageId = parameters[1];
+ const emoji = parameters[2];
- return;
- }
+ try {
+ const targetMessage = await message.channel.messages.fetch(messageId);
- await targetMessage.react(emoji);
- } catch (error) {
- console.error("Error reacting to message:", error);
+ if (!targetMessage) {
+ await message.reply("Message not found.");
- await message.reply("Failed to react to the message.");
+ return;
}
+
+ await targetMessage.react(emoji);
+ } catch (error) {
+ console.error("Error reacting to message:", error);
+
+ await message.reply("Failed to react to the message.");
+ }
};
diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts
index 31afb04..ec19a33 100644
--- a/packages/gateway/src/commands/say.ts
+++ b/packages/gateway/src/commands/say.ts
@@ -2,124 +2,124 @@ import { Message } from "discord.js";
import { GUILD_ID } from "../constants";
export const handleSayCommand = async (message: Message) => {
- if (message.author.bot) return;
+ if (message.author.bot) return;
- if (message.content.toLowerCase().startsWith("uma!say")) {
- const application = await message.client.application?.fetch();
- const ownerId = application?.owner?.id;
+ if (message.content.toLowerCase().startsWith("uma!say")) {
+ const application = await message.client.application?.fetch();
+ const ownerId = application?.owner?.id;
- if (message.author.id !== ownerId) return;
+ if (message.author.id !== ownerId) return;
- const parameters = message.content.split(" ").slice(1);
+ const parameters = message.content.split(" ").slice(1);
- if (parameters.length < 2) {
- await message.reply(
- "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`",
- );
+ if (parameters.length < 2) {
+ await message.reply(
+ "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`",
+ );
- return;
- }
+ return;
+ }
- const firstParameter = parameters[0];
- const messageContent = parameters.slice(1).join(" ");
- let targetChannel: any;
- let targetMessage: any = null;
- const messageIdMatch = firstParameter.match(/^\d{17,19}$/);
+ const firstParameter = parameters[0];
+ const messageContent = parameters.slice(1).join(" ");
+ let targetChannel: any;
+ let targetMessage: any = null;
+ const messageIdMatch = firstParameter.match(/^\d{17,19}$/);
- if (messageIdMatch) {
- try {
- const guild = message.client.guilds.cache.get(GUILD_ID);
+ if (messageIdMatch) {
+ try {
+ const guild = message.client.guilds.cache.get(GUILD_ID);
- if (!guild) {
- await message.reply("❌ Guild not found.");
+ if (!guild) {
+ await message.reply("❌ Guild not found.");
- return;
- }
+ return;
+ }
- let foundMessage = null;
+ let foundMessage = null;
- for (const channel of guild.channels.cache.values()) {
- if (channel.isTextBased()) {
- try {
- foundMessage = await channel.messages.fetch(firstParameter);
+ for (const channel of guild.channels.cache.values()) {
+ if (channel.isTextBased()) {
+ try {
+ foundMessage = await channel.messages.fetch(firstParameter);
- if (foundMessage) {
- targetChannel = channel;
- targetMessage = foundMessage;
+ if (foundMessage) {
+ targetChannel = channel;
+ targetMessage = foundMessage;
- break;
- }
- } catch {
- continue;
+ break;
}
+ } catch {
+ continue;
}
}
+ }
- if (!foundMessage) {
- await message.reply("❌ Message not found.");
-
- return;
- }
- } catch {
- await message.reply("❌ Error finding message.");
+ if (!foundMessage) {
+ await message.reply("❌ Message not found.");
return;
}
- } else {
- const channelMatch = firstParameter.match(/<#(\d+)>/);
+ } catch {
+ await message.reply("❌ Error finding message.");
- if (!channelMatch) {
- await message.reply(
- "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`",
- );
+ return;
+ }
+ } else {
+ const channelMatch = firstParameter.match(/<#(\d+)>/);
- return;
- }
+ if (!channelMatch) {
+ await message.reply(
+ "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`",
+ );
- const channelId = channelMatch[1];
+ return;
+ }
- targetChannel = message.client.channels.cache.get(channelId);
+ const channelId = channelMatch[1];
- if (!targetChannel || !targetChannel.isTextBased()) {
- await message.reply("❌ Channel not found or is not a text channel.");
+ targetChannel = message.client.channels.cache.get(channelId);
- return;
- }
+ if (!targetChannel || !targetChannel.isTextBased()) {
+ await message.reply("❌ Channel not found or is not a text channel.");
+
+ return;
}
+ }
- try {
- await message.delete();
-
- const baseDuration = Math.max(1, messageContent.length / 20);
- const complexityMultiplier =
- (messageContent.match(/[.!?]/g) || []).length * 0.5;
- const wordCount = messageContent.split(" ").length;
- const wordComplexityMultiplier = Math.min(wordCount / 10, 2);
- const typingDuration = Math.min(
- baseDuration + complexityMultiplier + wordComplexityMultiplier,
- 8,
- );
+ try {
+ await message.delete();
+
+ const baseDuration = Math.max(1, messageContent.length / 20);
+ const complexityMultiplier =
+ (messageContent.match(/[.!?]/g) || []).length * 0.5;
+ const wordCount = messageContent.split(" ").length;
+ const wordComplexityMultiplier = Math.min(wordCount / 10, 2);
+ const typingDuration = Math.min(
+ baseDuration + complexityMultiplier + wordComplexityMultiplier,
+ 8,
+ );
+
+ await (targetChannel as any).sendTyping();
+ await new Promise((resolve) =>
+ setTimeout(resolve, typingDuration * 1000),
+ );
+
+ if (targetMessage) {
+ await targetMessage.reply(messageContent);
+ } else {
+ await (targetChannel as any).send(messageContent);
+ }
+ } catch (error) {
+ console.error("Error executing say command:", error);
- await (targetChannel as any).sendTyping();
- await new Promise((resolve) =>
- setTimeout(resolve, typingDuration * 1000),
+ try {
+ await message.reply(
+ "❌ Failed to execute the say command. Please check permissions.",
);
-
- if (targetMessage) {
- await targetMessage.reply(messageContent);
- } else {
- await (targetChannel as any).send(messageContent);
- }
- } catch (error) {
- console.error("Error executing say command:", error);
-
- try {
- await message.reply(
- "❌ Failed to execute the say command. Please check permissions.",
- );
- } catch (replyError) {
- console.error("Failed to send error reply:", replyError);
- }
+ } catch (replyError) {
+ console.error("Failed to send error reply:", replyError);
}
}
+ }
};
diff --git a/packages/gateway/src/commands/start.ts b/packages/gateway/src/commands/start.ts
index b6c9300..9b8beb5 100644
--- a/packages/gateway/src/commands/start.ts
+++ b/packages/gateway/src/commands/start.ts
@@ -2,80 +2,78 @@ import { Message } from "discord.js";
import { sendProgressUpdate, executeBulkRoleAssignment } from "./utilities";
export const handleStartCommand = async (message: Message) => {
- if (message.author.bot) return;
+ if (message.author.bot) return;
- if (message.content.toLowerCase().startsWith("uma!start")) {
- const application = await message.client.application?.fetch();
- const ownerId = application?.owner?.id;
+ if (message.content.toLowerCase().startsWith("uma!start")) {
+ const application = await message.client.application?.fetch();
+ const ownerId = application?.owner?.id;
- if (message.author.id !== ownerId) return;
+ if (message.author.id !== ownerId) return;
- const parameters = message.content.split(" ").slice(1);
+ const parameters = message.content.split(" ").slice(1);
- if (parameters.length < 3) {
- await message.reply(
- "❌ Usage: `uma!start <role_mention> <channel_mention_or_category_id> <update_channel_id> [action]`\nExample: `uma!start @Participant #general 1415599617214513254 execute`",
- );
-
- return;
- }
-
- const roleMention = parameters[0];
- const channelOrCategory = parameters[1];
- const updateChannelId = parameters[2];
- const action = parameters[3] || "execute";
- const roleMatch = roleMention.match(/<@&(\d+)>/);
+ if (parameters.length < 3) {
+ await message.reply(
+ "❌ Usage: `uma!start <role_mention> <channel_mention_or_category_id> <update_channel_id> [action]`\nExample: `uma!start @Participant #general 1415599617214513254 execute`",
+ );
- if (!roleMatch) {
- await message.reply(
- "❌ Please mention a role. Example: `@Participant`",
- );
+ return;
+ }
- return;
- }
+ const roleMention = parameters[0];
+ const channelOrCategory = parameters[1];
+ const updateChannelId = parameters[2];
+ const action = parameters[3] || "execute";
+ const roleMatch = roleMention.match(/<@&(\d+)>/);
- const roleId = roleMatch[1];
- let channelId: string | undefined;
- let categoryId: string | undefined;
- const channelMatch = channelOrCategory.match(/<#(\d+)>/);
+ if (!roleMatch) {
+ await message.reply("❌ Please mention a role. Example: `@Participant`");
- if (channelMatch) {
- channelId = channelMatch[1];
- } else {
- categoryId = channelOrCategory;
- }
+ return;
+ }
- if (action !== "preview" && action !== "execute") {
- await message.reply("❌ Action must be either `preview` or `execute`");
+ const roleId = roleMatch[1];
+ let channelId: string | undefined;
+ let categoryId: string | undefined;
+ const channelMatch = channelOrCategory.match(/<#(\d+)>/);
- return;
- }
+ if (channelMatch) {
+ channelId = channelMatch[1];
+ } else {
+ categoryId = channelOrCategory;
+ }
- if (action === "preview") {
- await message.reply(
- "📋 Preview mode - this would check the specified channel(s) for users who have sent messages.",
- );
+ if (action !== "preview" && action !== "execute") {
+ await message.reply("❌ Action must be either `preview` or `execute`");
- return;
- }
+ return;
+ }
+ if (action === "preview") {
await message.reply(
- "🚀 Bulk role operation started! Check the progress channel for updates.",
+ "📋 Preview mode - this would check the specified channel(s) for users who have sent messages.",
);
- executeBulkRoleAssignment(
+ return;
+ }
+
+ await message.reply(
+ "🚀 Bulk role operation started! Check the progress channel for updates.",
+ );
+
+ executeBulkRoleAssignment(
+ message.client,
+ roleId,
+ updateChannelId,
+ channelId,
+ categoryId,
+ ).catch((error) => {
+ console.error("Bulk role assignment failed:", error);
+ sendProgressUpdate(
message.client,
- roleId,
+ "❌ Bulk role assignment failed due to an error",
updateChannelId,
- channelId,
- categoryId,
- ).catch((error) => {
- console.error("Bulk role assignment failed:", error);
- sendProgressUpdate(
- message.client,
- "❌ Bulk role assignment failed due to an error",
- updateChannelId,
- );
- });
- }
+ );
+ });
+ }
};
diff --git a/packages/gateway/src/commands/utilities.ts b/packages/gateway/src/commands/utilities.ts
index bc9892d..7aa49f0 100644
--- a/packages/gateway/src/commands/utilities.ts
+++ b/packages/gateway/src/commands/utilities.ts
@@ -591,7 +591,6 @@ export const executeBulkRoleAssignment = async (
if (error.code === 10007 || error.message?.includes("Unknown Member")) {
notInGuildCount += 1;
-
} else {
errorCount += 1;
}