diff --git a/discordWebhook.js b/discordWebhook.js index 73ec1a4..77e78f3 100644 --- a/discordWebhook.js +++ b/discordWebhook.js @@ -40,7 +40,7 @@ function sendDiscordNotification(content, additionalData = {}) { method: "POST", headers: { "Content-Type": "application/json", - "Content-Length": data.length + "Content-Length": Buffer.byteLength(data) } }; @@ -77,36 +77,80 @@ function notifyImageGenerated(config, ipAddress) { const username = sanitizeText(config.username) || "@unknown"; const displayName = sanitizeText(config.displayName) || "Unknown User"; - let content = `🖼️ **New Image Generated**\n`; - content += `User: ${displayName} (${username})\n`; + const fields = [ + { + name: "User", + value: `${displayName} (${username})`, + inline: false + } + ]; if (config.text) { const sanitized = sanitizeText(config.text); - const shortText = sanitized.length > 100 - ? sanitized.substring(0, 100) + "..." + const shortText = sanitized.length > 1000 + ? sanitized.substring(0, 1000) + "..." : sanitized; - content += `Text: ${shortText}\n`; + fields.push({ + name: "Text", + value: shortText || "No text", + inline: false + }); } if (ipAddress) { - content += `IP: ${ipAddress}\n`; + fields.push({ + name: "IP Address", + value: ipAddress, + inline: true + }); } - return sendDiscordNotification(content); + const embed = { + title: "🖼️ New Image Generated", + color: 0x5865F2, // blurple + fields: fields, + timestamp: new Date().toISOString() + }; + + return sendDiscordNotification("", { embeds: [embed] }); } // notify about new snapshot creation function notifySnapshotCreated(sessionId, token, ipAddress) { - let content = `📸 **New Snapshot Created**\n`; - content += `Session ID: ${sessionId}\n`; - content += `Token: ${token}\n`; - content += `Link: \`/v2/snapshot/${token}\`\n`; + const fields = [ + { + name: "Session ID", + value: sessionId, + inline: false + }, + { + name: "Token", + value: `\`${token}\``, + inline: false + }, + { + name: "Link", + value: `/v2/snapshot/${token}`, + inline: false + } + ]; if (ipAddress) { - content += `IP: ${ipAddress}`; + fields.push({ + name: "IP Address", + value: ipAddress, + inline: true + }); } - return sendDiscordNotification(content); + const embed = { + title: "📸 New Snapshot Created", + color: 0x57F287, // green + fields: fields, + timestamp: new Date().toISOString() + }; + + return sendDiscordNotification("", { embeds: [embed] }); }