import axios from 'axios'; import { ComplianceReport } from '../types'; export class DiscordNotifier { constructor(private webhookUrl: string) {} async notify(report: ComplianceReport): Promise { const { fileName, violations, summary } = report; const severityColor = (severity: string) => { switch (severity) { case 'critical': return 0xdc2626; case 'warning': return 0xf59e0b; case 'info': return 0x3b82f6; default: return 0x6b7280; } }; const embeds = [ { title: '🚨 Design Violations Detected', description: `**File:** ${fileName}\n**Total Violations:** ${summary.total}`, color: summary.bySeverity.critical ? severityColor('critical') : severityColor('warning'), fields: [ { name: '🔴 Critical', value: (summary.bySeverity.critical || 0).toString(), inline: true, }, { name: '🟡 Warnings', value: (summary.bySeverity.warning || 0).toString(), inline: true, }, { name: '🔵 Info', value: (summary.bySeverity.info || 0).toString(), inline: true, }, ], timestamp: new Date().toISOString(), }, ]; // Add top violations const topViolations = violations.slice(0, 3); for (const v of topViolations) { embeds.push({ title: `${v.type.toUpperCase()}`, description: v.message, color: severityColor(v.severity), fields: [ { name: 'Node', value: v.node.name, inline: true, }, { name: 'Severity', value: v.severity, inline: true, }, ], timestamp: new Date().toISOString(), }); } await axios.post(this.webhookUrl, { embeds, username: 'Design Compliance Bot', }); } }