import { Message } from "discord.js"; import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities"; import { parseCommandDurationToMilliseconds } from "./parseCommandDuration"; export const handleSaydCommand = async (message: Message): Promise => { if (message.author.bot) return false; const content = message.content.trim(); const commandMatch = content.match(/^uma!sayd\s+(\d+)\s+(\S+)\s+(.+)$/s); if (!commandMatch) return false; const [, channelId, timeout, messageContent] = commandMatch; const timeoutMilliseconds = parseCommandDurationToMilliseconds(timeout); if (!timeoutMilliseconds) { await replyWithCleanup( message, "❌ Invalid timeout format. Use: ``\nExamples: `10s`, `5m`, `1h`", ); return true; } if (!messageContent.trim()) { await replyWithCleanup( message, "❌ You need to provide a message to send.", ); return true; } try { const targetChannel = message.client.channels.cache.get(channelId); if ( !targetChannel || !targetChannel.isTextBased() || targetChannel.isDMBased() ) { await replyWithCleanup( message, "❌ Channel not found or is not a text channel.", ); return true; } const sentMessage = await targetChannel.send(messageContent); setTimeout(async () => { try { await sentMessage.delete(); } catch (error) { logUnexpectedDiscordAPIError(error); } }, timeoutMilliseconds); await replyWithCleanup( message, `✅ Message sent to <#${channelId}> and will be deleted in ${timeout}.`, ); return true; } catch (error) { logUnexpectedDiscordAPIError(error); await replyWithCleanup( message, "❌ Failed to send message to the specified channel.", ); return true; } };