feat: implement decoration to embeds

This commit is contained in:
João Gabriel
2024-12-22 00:44:25 -03:00
parent 055b59e6fa
commit 870e074825
7 changed files with 64 additions and 45 deletions

View File

@@ -505,7 +505,7 @@ export const sendDiscordNotificationWelcome = async (newAdmin: Auth) => {
webhookUrl: process.env.DISCORD_WEBHOOK_URL || "", webhookUrl: process.env.DISCORD_WEBHOOK_URL || "",
}, },
{ {
title: " New User Registered", title: "New User Registered",
color: 0x00ff00, color: 0x00ff00,
fields: [ fields: [
{ {

View File

@@ -187,11 +187,15 @@ export const notificationRouter = createTRPCRouter({
.input(apiTestDiscordConnection) .input(apiTestDiscordConnection)
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
try { try {
const decorate = (decoration: string, text: string) =>
`${input.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(input, { await sendDiscordNotification(input, {
title: "> `🤚` - Test Notification", title: decorate(">", "`🤚` - Test Notification"),
description: "> Hi, From Dokploy 👋", description: decorate(">", "Hi, From Dokploy 👋"),
color: 0xf3f7f4, color: 0xf3f7f4,
}); });
return true; return true;
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({

View File

@@ -59,46 +59,49 @@ export const sendBuildErrorNotifications = async ({
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: "> `⚠️` Build Failed", title: decorate(">", "`⚠️` Build Failed"),
color: 0xed4245, color: 0xed4245,
fields: [ fields: [
{ {
name: "`🛠️` Project", name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: "`⚙️` Application", name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: "`❔` Type", name: decorate("`❔`", "Type"),
value: applicationType, value: applicationType,
inline: true, inline: true,
}, },
{ {
name: "`📅` Date", name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: "`⌚` Time", name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: "`❓`Type", name: decorate("`❓`", "Type"),
value: "Failed", value: "Failed",
inline: true, inline: true,
}, },
{ {
name: "`⚠️` Error Message", name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${errorMessage}\`\`\``, value: `\`\`\`${errorMessage}\`\`\``,
}, },
{ {
name: "`🧷` Build Link", name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`, value: `[Click here to access build link](${buildLink})`,
}, },
], ],

View File

@@ -57,42 +57,45 @@ export const sendBuildSuccessNotifications = async ({
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: "> `✅` Build Success", title: "> `✅` Build Success",
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: "`🛠️` Project", name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: "`⚙️` Application", name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: "`❔` Application Type", name: decorate("`❔`", "Type"),
value: applicationType, value: applicationType,
inline: true, inline: true,
}, },
{ {
name: "`📅` Date", name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: "`⌚` Time", name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: "`❓` Type", name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },
{ {
name: "`🧷` Build Link", name: decorate("`🧷`", "Build Link"),
value: `[Click here to access build link](${buildLink})`, value: `[Click here to access build link](${buildLink})`,
}, },
], ],

View File

@@ -62,40 +62,43 @@ export const sendDatabaseBackupNotifications = async ({
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: title:
type === "success" type === "success"
? "> `✅` Database Backup Successful" ? decorate(">", "`✅` Database Backup Successful")
: "> `❌` Database Backup Failed", : decorate(">", "`❌` Database Backup Failed"),
color: type === "success" ? 0x57f287 : 0xed4245, color: type === "success" ? 0x57f287 : 0xed4245,
fields: [ fields: [
{ {
name: "`🛠️` Project", name: decorate("`🛠️`", "Project"),
value: projectName, value: projectName,
inline: true, inline: true,
}, },
{ {
name: "`⚙️` Application", name: decorate("`⚙️`", "Application"),
value: applicationName, value: applicationName,
inline: true, inline: true,
}, },
{ {
name: "`❔` Database", name: decorate("`❔`", "Database"),
value: databaseType, value: databaseType,
inline: true, inline: true,
}, },
{ {
name: "`📅` Date", name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: "`⌚` Time", name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: "`❓` Type", name: decorate("`❓`", "Type"),
value: type value: type
.replace("error", "Failed") .replace("error", "Failed")
.replace("success", "Successful"), .replace("success", "Successful"),
@@ -104,7 +107,7 @@ export const sendDatabaseBackupNotifications = async ({
...(type === "error" && errorMessage ...(type === "error" && errorMessage
? [ ? [
{ {
name: "`⚠️` Error Message", name: decorate("`⚠️`", "Error Message"),
value: `\`\`\`${errorMessage}\`\`\``, value: `\`\`\`${errorMessage}\`\`\``,
}, },
] ]

View File

@@ -45,27 +45,30 @@ export const sendDockerCleanupNotifications = async (
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: "> `✅` Docker Cleanup", title: decorate(">", "`✅` Docker Cleanup"),
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: "`📅` Date", name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: "`⌚` Time", name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: "`❓` Type", name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },
{ {
name: "`📜` Message", name: decorate("`📜`", "Message"),
value: `\`\`\`${message}\`\`\``, value: `\`\`\`${message}\`\`\``,
}, },
], ],

View File

@@ -34,22 +34,25 @@ export const sendDokployRestartNotifications = async () => {
} }
if (discord) { if (discord) {
const decorate = (decoration: string, text: string) =>
`${discord.decoration ? decoration : ""} ${text}`.trim();
await sendDiscordNotification(discord, { await sendDiscordNotification(discord, {
title: "> `✅` Dokploy Server Restarted", title: decorate(">", "`✅` Dokploy Server Restarted"),
color: 0x57f287, color: 0x57f287,
fields: [ fields: [
{ {
name: "`📅` Date", name: decorate("`📅`", "Date"),
value: `<t:${unixDate}:D>`, value: `<t:${unixDate}:D>`,
inline: true, inline: true,
}, },
{ {
name: "`⌚` Time", name: decorate("`⌚`", "Time"),
value: `<t:${unixDate}:t>`, value: `<t:${unixDate}:t>`,
inline: true, inline: true,
}, },
{ {
name: "`❓` Type", name: decorate("`❓`", "Type"),
value: "Successful", value: "Successful",
inline: true, inline: true,
}, },