diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
commit | 453683b57b8ff013ff25e2aaa4aa1d2e047edcb7 (patch) | |
tree | 8b98d2f30dbb6a8448602446cfacf9091667cc33 /src/arguments/messageLink.ts | |
parent | de4c3dcaf172804d34ae708be1ed3e75af42f4d5 (diff) | |
download | tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.gz tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.bz2 tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.zip |
a few small changes
Diffstat (limited to 'src/arguments/messageLink.ts')
-rw-r--r-- | src/arguments/messageLink.ts | 19 |
1 files changed, 19 insertions, 0 deletions
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; +}; |