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.ts30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts
index 6007b4e..f8b6ab1 100644
--- a/src/arguments/duration.ts
+++ b/src/arguments/duration.ts
@@ -1,21 +1,19 @@
import { BushArgumentTypeCaster } from '../lib/extensions/discord-akairo/BushArgumentTypeCaster';
import { BushMessage } from '../lib/extensions/discord.js/BushMessage';
-import { BushConstants } from '../lib/utils/BushConstants';
-export const durationTypeCaster: BushArgumentTypeCaster = async (_message: BushMessage, phrase): Promise<number> => {
- if (!phrase) return null;
+export const durationTypeCaster: BushArgumentTypeCaster = (_message: BushMessage, phrase): number => {
+ // if (!phrase) return null;
+ // const regexString = Object.entries(BushConstants.TimeUnits)
+ // .map(([name, { label }]) => String.raw`(?:(?<${name}>-?(?:\d+)?\.?\d+) *${label})?`)
+ // .join('\\s*');
+ // const match = new RegExp(`^${regexString}$`, 'im').exec(phrase);
+ // if (!match) return null;
+ // let milliseconds = 0;
+ // for (const key in match.groups) {
+ // const value = Number(match.groups[key] || 0);
+ // milliseconds += value * BushConstants.TimeUnits[key].value;
+ // }
+ // return milliseconds;
- 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);
- if (!match) return null;
-
- let milliseconds = 0;
- for (const key in match.groups) {
- const value = Number(match.groups[key] || 0);
- milliseconds += value * BushConstants.TimeUnits[key].value;
- }
-
- return milliseconds;
+ return client.util.parseDuration(phrase).duration;
};