aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/roleWithDuration.ts
blob: 455ad76504ff3ab18c8d4438a354651c61db3023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { type BushArgumentTypeCaster } from '#lib';

export const roleWithDurationTypeCaster: BushArgumentTypeCaster = async (
	message,
	phrase
): Promise<{ duration: number | null; role: string | null } | null> => {
	// eslint-disable-next-line prefer-const
	let { duration, contentWithoutTime } = client.util.parseDuration(phrase);
	if (contentWithoutTime === null || contentWithoutTime === undefined) return null;
	contentWithoutTime = contentWithoutTime.trim();
	const role = await util.arg.cast('role', message, contentWithoutTime);
	if (!role) return null;
	return { duration, role };
};