aboutsummaryrefslogtreecommitdiff
path: root/lib/arguments/roleWithDuration.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arguments/roleWithDuration.ts')
-rw-r--r--lib/arguments/roleWithDuration.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/arguments/roleWithDuration.ts b/lib/arguments/roleWithDuration.ts
new file mode 100644
index 0000000..b97f205
--- /dev/null
+++ b/lib/arguments/roleWithDuration.ts
@@ -0,0 +1,17 @@
+import { Arg, BushArgumentTypeCaster, parseDuration } from '#lib';
+import type { Role } from 'discord.js';
+
+export const roleWithDuration: BushArgumentTypeCaster<Promise<RoleWithDuration | null>> = async (message, phrase) => {
+ // eslint-disable-next-line prefer-const
+ let { duration, content } = parseDuration(phrase);
+ if (content === null || content === undefined) return null;
+ content = content.trim();
+ const role = await Arg.cast('role', message, content);
+ if (!role) return null;
+ return { duration, role };
+};
+
+export interface RoleWithDuration {
+ duration: number | null;
+ role: Role | null;
+}