diff options
| author | Natasha Moongrave <natasha@256phi.eu> | 2026-04-01 14:23:25 +0200 |
|---|---|---|
| committer | Natasha Moongrave <natasha@256phi.eu> | 2026-04-01 14:23:25 +0200 |
| commit | 276bbac65676a74d73fe7052537a1fb1fe554025 (patch) | |
| tree | 0e5ce19952e7ad3e0fc5d718bc48c7f0f984c77a /src/Pages/commissions/commissions.php | |
| parent | 3aa9e12bf1efc1da4f183b455e423037134f94b7 (diff) | |
Updated commissions and guestbook to be able to hook into a discord bot and send me notifications when a commissions is submited
Diffstat (limited to 'src/Pages/commissions/commissions.php')
| -rw-r--r-- | src/Pages/commissions/commissions.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Pages/commissions/commissions.php b/src/Pages/commissions/commissions.php index 215db6d..579845d 100644 --- a/src/Pages/commissions/commissions.php +++ b/src/Pages/commissions/commissions.php @@ -1,3 +1,58 @@ +<?php +// Load config from outside web root +$config = file_exists('/var/www/config.php') ? require '/var/www/config.php' : []; + +// Send Discord DM notification +function sendDiscordDM($config, $title, $message) { + if (empty($config['discord_bot_token']) || empty($config['discord_user_id'])) { + return false; + } + + $token = $config['discord_bot_token']; + $userId = $config['discord_user_id']; + + // Create/get DM channel + $ch = curl_init('https://discord.com/api/v10/users/@me/channels'); + curl_setopt_array($ch, [ + CURLOPT_HTTPHEADER => [ + 'Authorization: Bot ' . $token, + 'Content-Type: application/json', + ], + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => json_encode(['recipient_id' => $userId]), + CURLOPT_RETURNTRANSFER => true, + ]); + $response = json_decode(curl_exec($ch), true); + curl_close($ch); + + if (empty($response['id'])) { + return false; + } + + // Send message to DM channel + $ch = curl_init('https://discord.com/api/v10/channels/' . $response['id'] . '/messages'); + curl_setopt_array($ch, [ + CURLOPT_HTTPHEADER => [ + 'Authorization: Bot ' . $token, + 'Content-Type: application/json', + ], + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => json_encode([ + 'embeds' => [[ + 'title' => $title, + 'description' => $message, + 'color' => 0xff00ff, + 'timestamp' => date('c'), + ]] + ]), + CURLOPT_RETURNTRANSFER => true, + ]); + curl_exec($ch); + curl_close($ch); + + return true; +} +?> <!DOCTYPE html> <html lang="en"> <head> @@ -386,6 +441,10 @@ if (file_put_contents($submissionsFile, json_encode($submissions, JSON_PRETTY_PRINT))) { $success = true; + + // Send Discord notification + $dmMessage = "**From:** $name\n**Email:** $email\n**Budget:** " . ($budget ?: 'Not specified') . "\n\n**Description:**\n$description"; + sendDiscordDM($config, '🎨 New Commission Request', $dmMessage); } else { $error = 'Failed to save request. Please email me directly.'; } |
