aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/roleWithDuration.ts
blob: d619b9e4f2d2433a0abee38c7d4cffaba2b559b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { type BushArgumentTypeCaster } 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, 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 };
};

export interface RoleWithDuration {
	duration: number | null;
	role: Role | null;
}