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

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