summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-10-08 14:04:30 -0700
committerFuwn <[email protected]>2025-10-08 14:04:30 -0700
commit13857a31f99976803569466c146a5ac522114c49 (patch)
tree78aea2b4a3a589df64cdd182fa4f4c189275518c
parentrefactor: Move Discord interaction constants to shared constants package (diff)
downloadumabotdiscord-13857a31f99976803569466c146a5ac522114c49.tar.xz
umabotdiscord-13857a31f99976803569466c146a5ac522114c49.zip
fix(gateway:say): Improve reply handling
-rw-r--r--packages/gateway/src/commands/say.ts94
1 files changed, 40 insertions, 54 deletions
diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts
index 23c2880..831fe8c 100644
--- a/packages/gateway/src/commands/say.ts
+++ b/packages/gateway/src/commands/say.ts
@@ -16,81 +16,67 @@ export const handleSayCommand = async (message: Message) => {
if (parameters.length < 2) {
await replyWithCleanup(
message,
- "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`",
+ "❌ Usage: `uma!say <channel_id> [message_id] <message>`\nExamples:\n- `uma!say 1234567890123456789 Hello everyone!`\n- `uma!say 1234567890123456789 9876543210987654321 Thanks for the info!`",
);
return;
}
const firstParameter = parameters[0];
- const messageContent = parameters.slice(1).join(" ");
+ const secondParameter = parameters[1];
+ const messageContent = parameters.slice(2).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(CENTRAL_GUILD_ID);
-
- if (!guild) {
- await replyWithCleanup(message, "❌ Guild not found.");
-
- return;
- }
-
- let foundMessage = null;
+ const channelIdMatch = firstParameter.match(/^\d{17,19}$/);
+
+ if (!channelIdMatch) {
+ await replyWithCleanup(
+ message,
+ "❌ First parameter must be a channel ID (17-19 digits). Example: `1234567890123456789`",
+ );
- for (const channel of guild.channels.cache.values()) {
- if (channel.isTextBased()) {
- try {
- foundMessage = await channel.messages.fetch(firstParameter);
+ return;
+ }
- if (foundMessage) {
- targetChannel = channel;
- targetMessage = foundMessage;
+ targetChannel = message.client.channels.cache.get(firstParameter);
- break;
- }
- } catch {
- continue;
- }
- }
- }
+ if (!targetChannel || !targetChannel.isTextBased()) {
+ await replyWithCleanup(
+ message,
+ "❌ Channel not found or is not a text channel.",
+ );
- if (!foundMessage) {
- await replyWithCleanup(message, "❌ Message not found.");
+ return;
+ }
- return;
- }
+ const messageIdMatch = secondParameter?.match(/^\d{17,19}$/);
+
+ if (messageIdMatch) {
+ try {
+ targetMessage = await targetChannel.messages.fetch(secondParameter);
} catch {
- await replyWithCleanup(message, "❌ Error finding message.");
-
- return;
- }
- } else {
- const channelMatch = firstParameter.match(/<#(\d+)>/);
-
- if (!channelMatch) {
- await replyWithCleanup(
- message,
- "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`",
- );
+ await replyWithCleanup(message, "❌ Message not found in the specified channel.");
return;
}
+ }
- const channelId = channelMatch[1];
+ if (!messageIdMatch && parameters.length < 2) {
+ await replyWithCleanup(
+ message,
+ "❌ Usage: `uma!say <channel_id> [message_id] <message>`\nExamples:\n- `uma!say 1234567890123456789 Hello everyone!`\n- `uma!say 1234567890123456789 9876543210987654321 Thanks for the info!`",
+ );
- targetChannel = message.client.channels.cache.get(channelId);
+ return;
+ }
- if (!targetChannel || !targetChannel.isTextBased()) {
- await replyWithCleanup(
- message,
- "❌ Channel not found or is not a text channel.",
- );
+ if (messageIdMatch && parameters.length < 3) {
+ await replyWithCleanup(
+ message,
+ "❌ When providing a message ID, you need at least 3 parameters: channel_id, message_id, and message content.",
+ );
- return;
- }
+ return;
}
try {