From 7048fb1d6d24a26d4e0fdadc2f75bd0717fa80f9 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:29:20 -0400 Subject: more pain --- src/arguments/contentWithDuration.ts | 6 +++--- src/arguments/discordEmoji.ts | 17 +++++++++++++++++ src/arguments/duration.ts | 4 ++-- src/arguments/snowflake.ts | 8 ++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/arguments/discordEmoji.ts create mode 100644 src/arguments/snowflake.ts (limited to 'src/arguments') diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index 314b761..38b3fa4 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -1,8 +1,8 @@ -import { BushArgumentTypeCaster, BushMessage } from '@lib'; +import { BushArgumentTypeCaster } from '@lib'; export const contentWithDurationTypeCaster: BushArgumentTypeCaster = async ( - _message: BushMessage, - phrase: string + _, + phrase ): Promise<{ duration: number; contentWithoutTime: string | null }> => { return client.util.parseDuration(phrase); }; diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts new file mode 100644 index 0000000..9884c98 --- /dev/null +++ b/src/arguments/discordEmoji.ts @@ -0,0 +1,17 @@ +import { Snowflake } from 'discord-api-types'; +import { BushArgumentTypeCaster } from '../lib'; + +export const discordEmojiTypeCaster: BushArgumentTypeCaster = ( + _, + phrase +): { name: string; id: Snowflake; animated: boolean } | null => { + console.log(phrase); + if (!phrase) return null; + const validEmoji = client.consts.regex.discordEmoji.test(phrase); + console.log(validEmoji); + if (!validEmoji) return null; + const emoji = phrase.replace(/[<>]/g, '').split(':'); + const animated = emoji[0] === 'a'; + console.log(emoji); + return { name: emoji[1], id: emoji[2], animated }; +}; diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index ce181e8..6e76034 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,5 +1,5 @@ -import { BushArgumentTypeCaster, BushMessage } from '@lib'; +import { BushArgumentTypeCaster } from '@lib'; -export const durationTypeCaster: BushArgumentTypeCaster = (_message: BushMessage, phrase): number => { +export const durationTypeCaster: BushArgumentTypeCaster = (_, phrase): number => { return client.util.parseDuration(phrase).duration; }; diff --git a/src/arguments/snowflake.ts b/src/arguments/snowflake.ts new file mode 100644 index 0000000..0e6136f --- /dev/null +++ b/src/arguments/snowflake.ts @@ -0,0 +1,8 @@ +import { Snowflake } from 'discord.js'; +import { BushArgumentTypeCaster } from '../lib'; + +export const snowflakeTypeCaster: BushArgumentTypeCaster = (_, phrase): Snowflake | null => { + if (!phrase) return null; + if (client.consts.regex.snowflake.test(phrase)) return phrase; + return null; +}; -- cgit