<?php
$SECRET_PASSWORD = "AtaniRecodeIsFireRightNow-1KKRVcV7n6alfkda8m1NPP-gbc+g59=<3-6mvK44aXplbnv4WCD1OyDv";
$BOT_TOKEN = "MTM0OTgyNDM5MDI1ODQ5MTQxMg.GIPuoK.N8DzB5-cleezsOYQwY1RV2e1eQVIWiBn2-7Njo";
$CHANNEL_ID = "1342528823689875456";

function isValidKey($key, $secret) {
    $expectedKey = hash_hmac('sha256', 'wtfAtaniRecode???YOOOOnoWAYxD-5pIpewM8Pq4Xxn6yMN2uJx', $secret);
    return hash_equals($expectedKey, $key);
}

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(["success" => false, "error" => "Only POST requests allowed"]);
    exit;
}

if (!isset($_POST['key']) || !isset($_POST['report']) || !isset($_POST['computer'])) {
    http_response_code(400);
    echo json_encode(["success" => false, "error" => "Missing parameters"]);
    exit;
}

$key = $_POST['key'];
$report = $_POST['report'];
$computer = $_POST['computer'];
$cpu = $_POST['cpu'];
$gpu = $_POST['gpu'];
$ram = $_POST['ram'];

if (!isValidKey($key, $SECRET_PASSWORD)) {
    http_response_code(403);
    echo json_encode(["success" => false, "error" => "Invalid key"]);
    exit;
}

$embed = [
    "content" => "",
    "tts" => false,
    "embeds" => [
        [
            "title" => "Crash Report",
            "description" => "A crash occurred for **$computer**, their specifications are: \n\n🖥 **CPU**: `$cpu`\n🎮 **GPU**: `$gpu`\n💾 **RAM**: `$ram`\n\n```\n$report\n```",
            "color" => 2326507
        ]
    ]
];

$payload = json_encode($embed);

$ch = curl_init("https://discord.com/api/v9/channels/$CHANNEL_ID/messages");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bot $BOT_TOKEN",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

echo json_encode(["success" => true, "response" => $response]);
?>