aboutsummaryrefslogtreecommitdiff
path: root/lib/arguments/roleWithDuration.ts
blob: b97f205e0cc95c3fede356cb7f4d13116ef5cf25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
}