aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/discordEmoji.ts
blob: 92d65025f86983d8debcd2fae04e5c385a914d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { regex, type BushArgumentTypeCaster } from '#lib';
import type { Snowflake } from 'discord.js';

export const discordEmoji: BushArgumentTypeCaster<DiscordEmojiInfo | null> = (_, phrase) => {
	if (!phrase) return null;
	const validEmoji: RegExpExecArray | null = regex.discordEmoji.exec(phrase);
	if (!validEmoji || !validEmoji.groups) return null;
	return { name: validEmoji.groups.name, id: validEmoji.groups.id };
};

export interface DiscordEmojiInfo {
	name: string;
	id: Snowflake;
}