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.ts3
-rw-r--r--packages/gateway/src/commands/delete.ts11
-rw-r--r--packages/gateway/src/commands/pin.ts8
-rw-r--r--packages/gateway/src/commands/react.ts6
-rw-r--r--packages/gateway/src/commands/role.ts4
-rw-r--r--packages/gateway/src/commands/say.ts6
-rw-r--r--packages/gateway/src/commands/sayc.ts4
-rw-r--r--packages/gateway/src/commands/start.ts3
-rw-r--r--packages/gateway/src/commands/utilities.ts34
-rw-r--r--packages/gateway/src/commands/verbalGates.ts8
10 files changed, 39 insertions, 48 deletions
diff --git a/packages/gateway/src/commands/crp.ts b/packages/gateway/src/commands/crp.ts
index 4758574..70e611c 100644
--- a/packages/gateway/src/commands/crp.ts
+++ b/packages/gateway/src/commands/crp.ts
@@ -1,4 +1,5 @@
import { Message, Role } from "discord.js";
+import { logUnexpectedDiscordAPIError } from "../utilities";
export const handleCrpCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -88,7 +89,7 @@ export const handleCrpCommand = async (message: Message) => {
`✅ Successfully copied permissions from **${sourceRole.name}** to: **${targetRoleNames}**`,
);
} catch (error) {
- console.error("Error copying role permissions:", error);
+ logUnexpectedDiscordAPIError(error);
await message.reply(
"❌ Failed to copy role permissions. Check bot permissions and try again.",
);
diff --git a/packages/gateway/src/commands/delete.ts b/packages/gateway/src/commands/delete.ts
index bdbe585..32d6a85 100644
--- a/packages/gateway/src/commands/delete.ts
+++ b/packages/gateway/src/commands/delete.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handleDeleteCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -97,10 +97,7 @@ export const handleDeleteCommand = async (message: Message) => {
`Failed to fetch ${failedFetchCount} out of ${messageIds.length} messages for bulk delete`,
);
} catch (bulkError) {
- console.warn(
- "Bulk delete failed, falling back to individual deletion:",
- bulkError,
- );
+ logUnexpectedDiscordAPIError(bulkError);
let failedDeleteCount = 0;
@@ -136,7 +133,7 @@ export const handleDeleteCommand = async (message: Message) => {
);
}
} catch (error) {
- console.error("Error in bulk delete process:", error);
+ logUnexpectedDiscordAPIError(error);
await message.reply(
"❌ Failed to delete messages. Check bot permissions and try again.",
);
@@ -156,7 +153,7 @@ export const handleDeleteCommand = async (message: Message) => {
}
}
} catch (error) {
- console.error("Error deleting messages:", error);
+ logUnexpectedDiscordAPIError(error);
await message.reply(
"❌ Failed to delete messages. Check bot permissions and try again.",
);
diff --git a/packages/gateway/src/commands/pin.ts b/packages/gateway/src/commands/pin.ts
index 86f24be..884e41b 100644
--- a/packages/gateway/src/commands/pin.ts
+++ b/packages/gateway/src/commands/pin.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handlePinCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -97,7 +97,7 @@ export const handlePinCommand = async (message: Message) => {
});
}
} catch (error) {
- console.error(`Error processing message ${messageId}:`, error);
+ logUnexpectedDiscordAPIError(error);
results.push({
success: false,
messageId,
@@ -129,12 +129,12 @@ export const handlePinCommand = async (message: Message) => {
try {
await replyMessage.delete();
} catch (error) {
- console.error("Failed to delete result message:", error);
+ logUnexpectedDiscordAPIError(error);
}
}, 10000);
}
} catch (error) {
- console.error("Error pinning message:", error);
+ logUnexpectedDiscordAPIError(error);
if (
error instanceof Error &&
diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts
index 08e5822..bbe1fe9 100644
--- a/packages/gateway/src/commands/react.ts
+++ b/packages/gateway/src/commands/react.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handleReactCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -94,7 +94,7 @@ export const handleReactCommand = async (message: Message) => {
results.push(`Added ${emoji}`);
}
} catch (error) {
- console.error(`Error processing emoji ${emoji}:`, error);
+ logUnexpectedDiscordAPIError(error);
errors.push(emoji);
}
}
@@ -108,7 +108,7 @@ export const handleReactCommand = async (message: Message) => {
await replyWithCleanup(message, resultMessage);
} catch (error) {
- console.error("Error toggling reactions:", error);
+ logUnexpectedDiscordAPIError(error);
await replyWithCleanup(
message,
"❌ Failed to toggle reactions on the message.",
diff --git a/packages/gateway/src/commands/role.ts b/packages/gateway/src/commands/role.ts
index f0cbb29..3144aae 100644
--- a/packages/gateway/src/commands/role.ts
+++ b/packages/gateway/src/commands/role.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handleRoleCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -134,7 +134,7 @@ export const handleRoleCommand = async (message: Message) => {
`✅ ${actionText} for **${targetUser.username}** in **${guild.name}**.`,
);
} catch (error) {
- console.error("Error in role command:", error);
+ logUnexpectedDiscordAPIError(error);
await replyWithCleanup(
message,
"❌ Failed to manage role. Check bot permissions and try again.",
diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts
index 2783fb0..9df7abe 100644
--- a/packages/gateway/src/commands/say.ts
+++ b/packages/gateway/src/commands/say.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handleSayCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -107,7 +107,7 @@ export const handleSayCommand = async (message: Message) => {
await (targetChannel as any).send(messageContent);
}
} catch (error) {
- console.error("Error executing say command:", error);
+ logUnexpectedDiscordAPIError(error);
try {
await replyWithCleanup(
@@ -115,7 +115,7 @@ export const handleSayCommand = async (message: Message) => {
"❌ Failed to execute the say command. Please check permissions.",
);
} catch (replyError) {
- console.error("Failed to send error reply:", replyError);
+ logUnexpectedDiscordAPIError(replyError);
}
}
}
diff --git a/packages/gateway/src/commands/sayc.ts b/packages/gateway/src/commands/sayc.ts
index eafb2f1..2c8a28c 100644
--- a/packages/gateway/src/commands/sayc.ts
+++ b/packages/gateway/src/commands/sayc.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
export const handleSaycCommand = async (message: Message): Promise<boolean> => {
if (message.author.bot) return false;
@@ -41,7 +41,7 @@ export const handleSaycCommand = async (message: Message): Promise<boolean> => {
return true;
} catch (error) {
- console.error("Error in sayc command:", error);
+ logUnexpectedDiscordAPIError(error);
await replyWithCleanup(
message,
"❌ Failed to send message to the specified channel.",
diff --git a/packages/gateway/src/commands/start.ts b/packages/gateway/src/commands/start.ts
index 9b8beb5..d93df5f 100644
--- a/packages/gateway/src/commands/start.ts
+++ b/packages/gateway/src/commands/start.ts
@@ -1,5 +1,6 @@
import { Message } from "discord.js";
import { sendProgressUpdate, executeBulkRoleAssignment } from "./utilities";
+import { logUnexpectedDiscordAPIError } from "../utilities";
export const handleStartCommand = async (message: Message) => {
if (message.author.bot) return;
@@ -68,7 +69,7 @@ export const handleStartCommand = async (message: Message) => {
channelId,
categoryId,
).catch((error) => {
- console.error("Bulk role assignment failed:", error);
+ logUnexpectedDiscordAPIError(error);
sendProgressUpdate(
message.client,
"❌ Bulk role assignment failed due to an error",
diff --git a/packages/gateway/src/commands/utilities.ts b/packages/gateway/src/commands/utilities.ts
index 7ed18b4..8891074 100644
--- a/packages/gateway/src/commands/utilities.ts
+++ b/packages/gateway/src/commands/utilities.ts
@@ -1,5 +1,6 @@
import { Client, ChannelType } from "discord.js";
import { CENTRAL_GUILD_ID } from "../constants";
+import { logUnexpectedDiscordAPIError } from "../utilities";
export const AUDIT_LOG_GUILD_ID = "1419211292396224575";
export const AUDIT_LOG_CHANNEL_ID = "1419211778793144411";
@@ -14,7 +15,7 @@ export const sendProgressUpdate = async (
if (channel && "send" in channel) await (channel as any).send(message);
} catch (error) {
- console.error("Failed to send progress update:", error);
+ logUnexpectedDiscordAPIError(error);
}
};
@@ -72,7 +73,7 @@ export const sendAuditLog = async (
}
}
} catch (error) {
- console.error("Failed to send audit log:", error);
+ logUnexpectedDiscordAPIError(error);
}
};
@@ -121,10 +122,7 @@ export const fetchMessagesFromChannel = async (
await new Promise((resolve) => setTimeout(resolve, 100));
} catch (error) {
- console.error(
- `Error fetching messages from channel ${channel.id}:`,
- error,
- );
+ logUnexpectedDiscordAPIError(error);
hasMoreMessages = false;
}
@@ -175,11 +173,11 @@ export const fetchForumPosts = async (
updateChannelId,
);
} catch (error) {
- console.error(`Error processing forum post ${thread.id}:`, error);
+ logUnexpectedDiscordAPIError(error);
}
}
} catch (error) {
- console.error(`Error fetching forum posts from ${forumChannel.id}:`, error);
+ logUnexpectedDiscordAPIError(error);
}
return { messageCount: totalMessageCount, batchCount: totalBatchCount };
@@ -227,12 +225,12 @@ export const fetchChannelThreads = async (
updateChannelId,
);
} catch (error) {
- console.error(`Error processing thread ${thread.id}:`, error);
+ logUnexpectedDiscordAPIError(error);
}
}
}
} catch (error) {
- console.error(`Error fetching threads from ${textChannel.id}:`, error);
+ logUnexpectedDiscordAPIError(error);
}
return { messageCount: totalMessageCount, batchCount: totalBatchCount };
@@ -442,10 +440,7 @@ export const getAllChannelsInCategory = async (
channelNames[thread.id] = `🧵 ${getChannelName(thread)}`;
}
} catch (error) {
- console.error(
- `Error fetching threads for channel ${channel.id}:`,
- error,
- );
+ logUnexpectedDiscordAPIError(error);
}
}
@@ -464,10 +459,7 @@ export const getAllChannelsInCategory = async (
channelNames[thread.id] = `📝 ${getChannelName(thread)}`;
}
} catch (error) {
- console.error(
- `Error fetching forum posts for channel ${channel.id}:`,
- error,
- );
+ logUnexpectedDiscordAPIError(error);
}
}
}
@@ -546,7 +538,7 @@ export const sendPersonaLog = async (
await (channel as any).send({ embeds: [embed] });
} catch (error) {
- console.error("Failed to send persona log:", error);
+ logUnexpectedDiscordAPIError(error);
}
};
@@ -653,7 +645,7 @@ export const executeBulkRoleAssignment = async (
await new Promise((resolve) => setTimeout(resolve, 200));
} catch (error: any) {
- console.error(`Error processing user ${userId}:`, error);
+ logUnexpectedDiscordAPIError(error);
if (error.code === 10007 || error.message?.includes("Unknown Member")) {
notInGuildCount += 1;
@@ -669,7 +661,7 @@ export const executeBulkRoleAssignment = async (
customUpdateChannelId,
);
} catch (error) {
- console.error("Error in bulk role assignment:", error);
+ logUnexpectedDiscordAPIError(error);
await sendProgressUpdate(
client,
"❌ An error occurred during bulk role assignment",
diff --git a/packages/gateway/src/commands/verbalGates.ts b/packages/gateway/src/commands/verbalGates.ts
index 1fb655b..6032b86 100644
--- a/packages/gateway/src/commands/verbalGates.ts
+++ b/packages/gateway/src/commands/verbalGates.ts
@@ -1,5 +1,5 @@
import { Message } from "discord.js";
-import { replyWithCleanup } from "../utilities";
+import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities";
import { ROLEPLAY_GUILD_ID } from "../constants";
const RACECOURSES_CATEGORY_ID = "1428169113754402836";
@@ -120,7 +120,7 @@ export const handleVerbalGatesCommand = async (
try {
await message.react("✅");
} catch (error) {
- console.error("Error reacting to message:", error);
+ logUnexpectedDiscordAPIError(error);
}
return true;
@@ -149,12 +149,12 @@ export const handleVerbalGatesCommand = async (
try {
await message.react("✅");
} catch (error) {
- console.error("Error reacting to message:", error);
+ logUnexpectedDiscordAPIError(error);
}
return true;
} catch (error) {
- console.error("Error in verbal gates command:", error);
+ logUnexpectedDiscordAPIError(error);
await replyWithCleanup(
message,
"❌ An error occurred while managing channel permissions.",