diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-27 18:08:14 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-27 18:08:14 -0400 |
commit | 747b3c8302245699294b671d19b3d31d63f80bc1 (patch) | |
tree | ad3d987bb38d5bdaed67e6aca1263fb06331f746 /src/arguments | |
parent | 4176b6258e44e4a095376aaf0f4c687244243a69 (diff) | |
download | tanzanite-747b3c8302245699294b671d19b3d31d63f80bc1.tar.gz tanzanite-747b3c8302245699294b671d19b3d31d63f80bc1.tar.bz2 tanzanite-747b3c8302245699294b671d19b3d31d63f80bc1.zip |
did this a while ago so I don't remeber what I did
Diffstat (limited to 'src/arguments')
-rw-r--r-- | src/arguments/contentWithDuration.ts | 0 | ||||
-rw-r--r-- | src/arguments/duration.ts | 40 |
2 files changed, 3 insertions, 37 deletions
diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/arguments/contentWithDuration.ts diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index a2f7751..7b7a922 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,45 +1,11 @@ import { BushArgumentTypeCaster } from '../lib/extensions/BushArgumentTypeCaster'; import { BushMessage } from '../lib/extensions/BushMessage'; +import { BushConstants } from '../lib/utils/BushConstants'; -// Stolen from @Mzato0001 (pr to discord akairo that hasn't been merged yet) -const TimeUnits = { - years: { - label: '(?:years?|y)', - value: 1000 * 60 * 60 * 24 * 365 - }, - months: { - label: '(?:months?|mo)', - value: 1000 * 60 * 60 * 24 * 30 - }, - weeks: { - label: '(?:weeks?|w)', - value: 1000 * 60 * 60 * 24 * 7 - }, - days: { - label: '(?:days?|d)', - value: 1000 * 60 * 60 * 24 - }, - hours: { - label: '(?:hours?|hrs?|h)', - value: 1000 * 60 * 60 - }, - minutes: { - label: '(?:minutes?|mins?|m)', - value: 1000 * 60 - }, - seconds: { - label: '(?:seconds?|secs?|s)', - value: 1000 - }, - milliseconds: { - label: '(?:milliseconds?|msecs?|ms)', - value: 1 - } -}; export const durationTypeCaster: BushArgumentTypeCaster = async (_message: BushMessage, phrase): Promise<number> => { if (!phrase) return null; - const regexString = Object.entries(TimeUnits) + const regexString = Object.entries(BushConstants.TimeUnits) .map(([name, { label }]) => String.raw`(?:(?<${name}>-?(?:\d+)?\.?\d+) *${label})?`) .join('\\s*'); const match = new RegExp(`^${regexString}$`, 'i').exec(phrase); @@ -48,7 +14,7 @@ export const durationTypeCaster: BushArgumentTypeCaster = async (_message: BushM let milliseconds = 0; for (const key in match.groups) { const value = Number(match.groups[key] || 0); - milliseconds += value * TimeUnits[key].value; + milliseconds += value * BushConstants.TimeUnits[key].value; } return milliseconds; |