import { Client, Guild, PermissionsBitField } from 'discord.js'; import type { MahojiClient } from 'mahoji'; const discordEpoch = 1_420_070_400_000; export function randomSnowflake(): string { const timestamp = Date.now() - discordEpoch; const workerId = Math.floor(Math.random() * 32); const processId = Math.floor(Math.random() * 32); const increment = Math.floor(Math.random() * 4096); const timestampPart = BigInt(timestamp) << 22n; const workerIdPart = BigInt(workerId) << 17n; const processIdPart = BigInt(processId) << 12n; const incrementPart = BigInt(increment); const snowflakeBigInt = timestampPart | workerIdPart | processIdPart | incrementPart; return snowflakeBigInt.toString(); } export function mentionCommand( client: Client & { mahojiClient: MahojiClient }, name: string, subCommand?: string, subSubCommand?: string ) { const command = client.mahojiClient.commands.values.find(i => i.name === name); if (!command) { throw new Error(`Command ${name} not found`); } if (subCommand && !command.options.some(i => i.name === subCommand)) { throw new Error(`Command ${name} does not have subcommand ${subCommand}`); } const apiCommand = client.application ? Array.from(client.application.commands.cache.values()).find(i => i.name === name) : null; if (!apiCommand) { throw new Error(`Command ${name} not found`); } if (subCommand) { return ``; } return ``; } export async function hasBanMemberPerms(userID: string, guild: Guild) { const member = await guild.members.fetch(userID).catch(() => null); if (!member) return false; return member.permissions.has(PermissionsBitField.Flags.BanMembers); }