From 453683b57b8ff013ff25e2aaa4aa1d2e047edcb7 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sun, 28 Nov 2021 09:27:41 -0500 Subject: a few small changes --- src/arguments/messageLink.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/arguments/messageLink.ts (limited to 'src/arguments/messageLink.ts') diff --git a/src/arguments/messageLink.ts b/src/arguments/messageLink.ts new file mode 100644 index 0000000..d270abd --- /dev/null +++ b/src/arguments/messageLink.ts @@ -0,0 +1,19 @@ +import { type BushArgumentTypeCaster } from '../lib'; + +export const messageLink: BushArgumentTypeCaster = async (_, phrase) => { + const match = client.consts.regex.messageLink.exec(phrase); + if (!match || !match.groups) return null; + + const { guild_id, channel_id, message_id } = match.groups; + + if (!guild_id || !channel_id || message_id) return null; + + const guild = client.guilds.cache.get(guild_id); + if (!guild) return null; + + const channel = guild.channels.cache.get(channel_id); + if (!channel || (!channel.isText() && !channel.isThread())) return null; + + const message = await channel.messages.fetch(message_id).catch(() => null); + return message; +}; -- cgit