Add Discord notifications for image generation and snapshot creation
This commit is contained in:
@@ -3,6 +3,16 @@ const https = require("https");
|
||||
|
||||
const WEBHOOK_URL = "https://discord.com/api/webhooks/1456729066924277912/zf0-cSqmU18kX-S5UZJHNwsuqKtM2i7Bp8LMCyXM80n1RsDtFQCTccBIzafghf7q-U4q";
|
||||
|
||||
// sanitze text for discord
|
||||
function sanitizeText(text) {
|
||||
if (!text) return "";
|
||||
|
||||
// remove or replace problematic characters
|
||||
return text
|
||||
.replace(/[\u0000-\u001F\u007F-\u009F]/g, "") // remove control chars
|
||||
.substring(0, 1800); // limit length to avoid discord limits
|
||||
}
|
||||
|
||||
// send notfication to discord
|
||||
function sendDiscordNotification(content, additionalData = {}) {
|
||||
if (!WEBHOOK_URL) {
|
||||
@@ -15,7 +25,13 @@ function sendDiscordNotification(content, additionalData = {}) {
|
||||
...additionalData
|
||||
};
|
||||
|
||||
const data = JSON.stringify(payload);
|
||||
let data;
|
||||
try {
|
||||
data = JSON.stringify(payload);
|
||||
} catch (err) {
|
||||
console.error("Failed to stringify webhook payload:", err);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const url = new URL(WEBHOOK_URL);
|
||||
const options = {
|
||||
@@ -58,16 +74,17 @@ function sendDiscordNotification(content, additionalData = {}) {
|
||||
|
||||
// notify about new image generation
|
||||
function notifyImageGenerated(config, ipAddress) {
|
||||
const username = config.username || "@unknown";
|
||||
const displayName = config.displayName || "Unknown User";
|
||||
const username = sanitizeText(config.username) || "@unknown";
|
||||
const displayName = sanitizeText(config.displayName) || "Unknown User";
|
||||
|
||||
let content = `🖼️ **New Image Generated**\n`;
|
||||
content += `User: ${displayName} (${username})\n`;
|
||||
|
||||
if (config.text) {
|
||||
const shortText = config.text.length > 100
|
||||
? config.text.substring(0, 100) + "..."
|
||||
: config.text;
|
||||
const sanitized = sanitizeText(config.text);
|
||||
const shortText = sanitized.length > 100
|
||||
? sanitized.substring(0, 100) + "..."
|
||||
: sanitized;
|
||||
content += `Text: ${shortText}\n`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user