import type { DirigentConfig } from "../rules.js"; function userIdFromToken(token: string): string | undefined { try { const segment = token.split(".")[0]; const padded = segment + "=".repeat((4 - (segment.length % 4)) % 4); return Buffer.from(padded, "base64").toString("utf8"); } catch { return undefined; } } export function extractMentionedUserIds(content: string): string[] { const regex = /<@!?(\d+)>/g; const ids: string[] = []; const seen = new Set(); let match: RegExpExecArray | null; while ((match = regex.exec(content)) !== null) { const id = match[1]; if (!seen.has(id)) { seen.add(id); ids.push(id); } } return ids; } export function getModeratorUserId(config: DirigentConfig): string | undefined { if (!config.moderatorBotToken) return undefined; return userIdFromToken(config.moderatorBotToken); }