summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/gateway/src/commands/pin.ts48
1 files changed, 45 insertions, 3 deletions
diff --git a/packages/gateway/src/commands/pin.ts b/packages/gateway/src/commands/pin.ts
index 4980d43..1667c50 100644
--- a/packages/gateway/src/commands/pin.ts
+++ b/packages/gateway/src/commands/pin.ts
@@ -14,18 +14,60 @@ export const handlePinCommand = async (message: Message) => {
const parameters = message.content.split(" ");
if (parameters.length < 2) {
- await replyWithCleanup(message, "❌ Usage: `uma!pin <message_id>`");
+ await replyWithCleanup(
+ message,
+ "❌ Usage: `uma!pin <message_id> [channel_id]`",
+ );
return;
}
const messageId = parameters[1];
+ const channelId = parameters[2];
+
+ if (!/^\d{17,19}$/.test(messageId)) {
+ await replyWithCleanup(
+ message,
+ "❌ Invalid message ID format. Please provide a valid Discord message ID.",
+ );
+
+ return;
+ }
+
+ if (channelId && !/^\d{17,19}$/.test(channelId)) {
+ await replyWithCleanup(
+ message,
+ "❌ Invalid channel ID format. Please provide a valid Discord channel ID.",
+ );
+
+ return;
+ }
try {
- const targetMessage = await message.channel.messages.fetch(messageId);
+ let targetChannel = message.channel;
+
+ if (channelId) {
+ const specifiedChannel = message.client.channels.cache.get(channelId);
+
+ if (!specifiedChannel || !specifiedChannel.isTextBased()) {
+ await replyWithCleanup(
+ message,
+ "❌ Channel not found or is not a text channel.",
+ );
+
+ return;
+ }
+
+ targetChannel = specifiedChannel;
+ }
+
+ const targetMessage = await targetChannel.messages.fetch(messageId);
if (!targetMessage) {
- await replyWithCleanup(message, "❌ Message not found.");
+ await replyWithCleanup(
+ message,
+ "❌ Message not found in the specified channel.",
+ );
return;
}