mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-08-22 08:34:13 -05:00
Add admin reports discord webhook
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"use server";
|
||||
|
||||
import nodemailer from "nodemailer";
|
||||
import { APIEmbed } from "discord-api-types/v10";
|
||||
import { sendDiscordMessageEmbed } from "@/utils/discord";
|
||||
|
||||
export interface ContactActionState {
|
||||
error: string | null;
|
||||
@@ -102,6 +104,25 @@ export async function sendContact(prev: ContactActionState, formData: FormData):
|
||||
text: confirmationMessage,
|
||||
});
|
||||
|
||||
// Send Discord notification
|
||||
if (process.env.DISCORD_WEBHOOK_ADMIN_REPORTS_URL) {
|
||||
const embed: APIEmbed = {
|
||||
title: `📧 ${topicLabels[topic]}`,
|
||||
description: message.length > 4096 ? message.substring(0, 4093) + "..." : message,
|
||||
color: topic === "security" ? 0xff0000 : topic === "bug" ? 0xffa500 : 0x3498db,
|
||||
fields: [
|
||||
...(name ? [{ name: "Name", value: name, inline: true }] : []),
|
||||
{ name: "Email", value: email, inline: true },
|
||||
...(contextUrl ? [{ name: "Related URL", value: contextUrl, inline: false }] : []),
|
||||
],
|
||||
footer: {
|
||||
text: `Ticket #${ticketId}`,
|
||||
},
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await sendDiscordMessageEmbed(process.env.DISCORD_WEBHOOK_ADMIN_REPORTS_URL, [embed]);
|
||||
}
|
||||
|
||||
return { error: null, success: `Your message was sent. Ticket #${ticketId}.` };
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : "Failed to send message.";
|
||||
|
||||
@@ -368,9 +368,9 @@ export async function submitHackReport(data: {
|
||||
}
|
||||
|
||||
// Send Discord webhook
|
||||
if (process.env.DISCORD_WEBHOOK_ADMIN_URL) {
|
||||
if (process.env.DISCORD_WEBHOOK_ADMIN_REPORTS_URL) {
|
||||
try {
|
||||
await sendDiscordMessageEmbed(process.env.DISCORD_WEBHOOK_ADMIN_URL, [
|
||||
await sendDiscordMessageEmbed(process.env.DISCORD_WEBHOOK_ADMIN_REPORTS_URL, [
|
||||
{
|
||||
title: "Hack Report",
|
||||
description: `A new report has been submitted for [${hack.title}](${hackUrl})`,
|
||||
|
||||
Reference in New Issue
Block a user