Add Discord notifications for image generation and snapshot creation
This commit is contained in:
@@ -40,7 +40,7 @@ function sendDiscordNotification(content, additionalData = {}) {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"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 username = sanitizeText(config.username) || "@unknown";
|
||||||
const displayName = sanitizeText(config.displayName) || "Unknown User";
|
const displayName = sanitizeText(config.displayName) || "Unknown User";
|
||||||
|
|
||||||
let content = `🖼️ **New Image Generated**\n`;
|
const fields = [
|
||||||
content += `User: ${displayName} (${username})\n`;
|
{
|
||||||
|
name: "User",
|
||||||
|
value: `${displayName} (${username})`,
|
||||||
|
inline: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
if (config.text) {
|
if (config.text) {
|
||||||
const sanitized = sanitizeText(config.text);
|
const sanitized = sanitizeText(config.text);
|
||||||
const shortText = sanitized.length > 100
|
const shortText = sanitized.length > 1000
|
||||||
? sanitized.substring(0, 100) + "..."
|
? sanitized.substring(0, 1000) + "..."
|
||||||
: sanitized;
|
: sanitized;
|
||||||
content += `Text: ${shortText}\n`;
|
fields.push({
|
||||||
|
name: "Text",
|
||||||
|
value: shortText || "No text",
|
||||||
|
inline: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipAddress) {
|
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
|
// notify about new snapshot creation
|
||||||
function notifySnapshotCreated(sessionId, token, ipAddress) {
|
function notifySnapshotCreated(sessionId, token, ipAddress) {
|
||||||
let content = `📸 **New Snapshot Created**\n`;
|
const fields = [
|
||||||
content += `Session ID: ${sessionId}\n`;
|
{
|
||||||
content += `Token: ${token}\n`;
|
name: "Session ID",
|
||||||
content += `Link: \`/v2/snapshot/${token}\`\n`;
|
value: sessionId,
|
||||||
|
inline: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Token",
|
||||||
|
value: `\`${token}\``,
|
||||||
|
inline: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Link",
|
||||||
|
value: `/v2/snapshot/${token}`,
|
||||||
|
inline: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
if (ipAddress) {
|
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] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user