Aethel Bot OSS repository!
aethel.xyz
bot
fun
ai
discord
discord-bot
aethel
1export function random<T>(array: T[]): T | undefined {
2 if (array.length === 0) {
3 return undefined;
4 }
5 return array[Math.floor(Math.random() * array.length)];
6}
7
8export function iso2ToFlagEmoji(iso2: string): string {
9 if (!iso2 || iso2.length !== 2) return '';
10 const upper = iso2.toUpperCase();
11 if (!/^[A-Z]{2}$/.test(upper)) return '';
12 const codePoints = upper.split('').map((char) => 0x1f1e6 + char.charCodeAt(0) - 65);
13 if (codePoints.some((cp) => cp < 0x1f1e6 || cp > 0x1f1ff)) return '';
14 return String.fromCodePoint(...codePoints);
15}
16
17export function iso2ToDiscordFlag(iso2: string): string {
18 if (!iso2 || iso2.length !== 2) return '';
19 return `:flag_${iso2.toLowerCase()}:`;
20}