(event)
| 24 | }; |
| 25 | |
| 26 | function buildModerationLogData(event) { |
| 27 | const targetIdMatch = event.target?.match(/\((\d+)\)/); |
| 28 | const targetId = targetIdMatch?.[1]; |
| 29 | const executorIdMatch = event.executor?.match(/\((\d+)\)/); |
| 30 | const executorTag = event.executor?.split(' (')[0] || 'Moderator'; |
| 31 | |
| 32 | const lines = []; |
| 33 | if (event.target) { |
| 34 | lines.push(formatLogLine('User', event.target)); |
| 35 | } |
| 36 | if (event.reason) { |
| 37 | const reason = event.reason.length > 900 |
| 38 | ? `${event.reason.substring(0, 897)}...` |
| 39 | : event.reason; |
| 40 | lines.push(formatLogLine('Reason', reason)); |
| 41 | } |
| 42 | if (event.duration) { |
| 43 | lines.push(formatLogLine('Duration', event.duration)); |
| 44 | } |
| 45 | if (event.caseId) { |
| 46 | lines.push(formatLogLine('Case', `\`${event.caseId}\``)); |
| 47 | } |
| 48 | |
| 49 | const meta = []; |
| 50 | if (event.metadata) { |
| 51 | Object.entries(event.metadata).forEach(([key, value]) => { |
| 52 | if (value !== undefined && value !== null && key !== 'userId' && key !== 'moderatorId') { |
| 53 | meta.push([key.charAt(0).toUpperCase() + key.slice(1), String(value)]); |
| 54 | } |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | const title = event.caseId ? `${event.action} · Case #${event.caseId}` : event.action; |
| 59 | |
| 60 | return { |
| 61 | title, |
| 62 | lines, |
| 63 | meta, |
| 64 | userId: event.metadata?.userId || targetId || undefined, |
| 65 | thumbnail: targetId ? `https://cdn.discordapp.com/embed/avatars/${Number(targetId) % 5}.png` : undefined, |
| 66 | footer: executorIdMatch |
| 67 | ? { text: executorTag, iconURL: undefined } |
| 68 | : undefined, |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | export async function logEvent({ client, guild, guildId, event }) { |
| 73 | try { |
no test coverage detected