aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/duration.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/arguments/duration.ts')
-rw-r--r--src/arguments/duration.ts40
1 files changed, 3 insertions, 37 deletions
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;