diff options
| author | Fuwn <[email protected]> | 2025-10-16 00:02:40 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-16 00:02:40 -0700 |
| commit | 357657bfe89e098a6c614a53e576c0414f82d6d1 (patch) | |
| tree | e659478455be0ebb4a9003dd480f9ca3d39d4cd3 /packages/gateway/src/commands/sayc.ts | |
| parent | feat(gateway:messageCreate): Refine welcome constants (diff) | |
| download | umabotdiscord-357657bfe89e098a6c614a53e576c0414f82d6d1.tar.xz umabotdiscord-357657bfe89e098a6c614a53e576c0414f82d6d1.zip | |
feat(gateway:commands): Add sayc command
Diffstat (limited to 'packages/gateway/src/commands/sayc.ts')
| -rw-r--r-- | packages/gateway/src/commands/sayc.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/gateway/src/commands/sayc.ts b/packages/gateway/src/commands/sayc.ts new file mode 100644 index 0000000..eafb2f1 --- /dev/null +++ b/packages/gateway/src/commands/sayc.ts @@ -0,0 +1,52 @@ +import { Message } from "discord.js"; +import { replyWithCleanup } from "../utilities"; + +export const handleSaycCommand = async (message: Message): Promise<boolean> => { + if (message.author.bot) return false; + + const content = message.content.trim(); + const commandMatch = content.match(/^uma!sayc\s+(\d+)\s+(.+)$/s); + + if (!commandMatch) return false; + + const [, channelId, messageContent] = commandMatch; + + 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; + } + + await targetChannel.send(messageContent); + await replyWithCleanup(message, `✅ Message sent to <#${channelId}>.`); + + return true; + } catch (error) { + console.error("Error in sayc command:", error); + await replyWithCleanup( + message, + "❌ Failed to send message to the specified channel.", + ); + + return true; + } +}; |