aboutsummaryrefslogtreecommitdiff
path: root/src/Pages/guestbook
diff options
context:
space:
mode:
authorNatasha Moongrave <natasha@256phi.eu>2026-04-01 14:23:25 +0200
committerNatasha Moongrave <natasha@256phi.eu>2026-04-01 14:23:25 +0200
commit276bbac65676a74d73fe7052537a1fb1fe554025 (patch)
tree0e5ce19952e7ad3e0fc5d718bc48c7f0f984c77a /src/Pages/guestbook
parent3aa9e12bf1efc1da4f183b455e423037134f94b7 (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/guestbook')
-rw-r--r--src/Pages/guestbook/guestbook.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Pages/guestbook/guestbook.php b/src/Pages/guestbook/guestbook.php
index 4aea11d..208a272 100644
--- a/src/Pages/guestbook/guestbook.php
+++ b/src/Pages/guestbook/guestbook.php
@@ -4,6 +4,60 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
+// 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' => 0x00ffff,
+ 'timestamp' => date('c'),
+ ]]
+ ]),
+ CURLOPT_RETURNTRANSFER => true,
+ ]);
+ curl_exec($ch);
+ curl_close($ch);
+
+ return true;
+}
+
$dataFile = __DIR__ . '/guestbook.json';
// Make sure the JSON file exists
@@ -47,6 +101,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Save back to JSON file
if (file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT)) === false) {
echo "<p style='color:red'>Error: Could not save guestbook entry. Check file permissions.</p>";
+ } else {
+ // Send Discord notification
+ $dmMessage = "**From:** {$entry['name']}\n\n{$entry['message']}";
+ sendDiscordDM($config, '📝 New Guestbook Entry', $dmMessage);
}
// Redirect to avoid form resubmission