aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/roleWithDuation.ts
blob: 03a6035647313b88b1eb3634886636238964881d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
	contentWithoutTime = contentWithoutTime.trim();
	const role = await util.arg.cast('role', client.commandHandler.resolver, message, contentWithoutTime);
	if (!role) {
		client.console.debug(contentWithoutTime);
		client.console.debug(duration);
		return null;
	}
	return { duration, role };
};