aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/permission.ts
blob: cf4c42c2d7acc1f7ef7cd22a8ca32eb04ab6906c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
import { type BushArgumentTypeCaster } from '#lib';
import { PermissionFlagsBits, type PermissionsString } from 'discord.js';

export const permission: BushArgumentTypeCaster<PermissionsString | null> = (_, phrase) => {
	if (!phrase) return null;
	phrase = phrase.toUpperCase().replace(/ /g, '_');
	if (!(phrase in PermissionFlagsBits)) {
		return null;
	} else {
		return phrase as PermissionsString;
	}
};