diff --git a/Discord Kofi/form.json b/Discord Kofi/form.json new file mode 100644 index 0000000..427505f --- /dev/null +++ b/Discord Kofi/form.json @@ -0,0 +1,17 @@ +{ + "elements": + [ + { "type": "ValidationTextBox", "name": "Title", "caption": "Titel" }, + { "type": "ValidationTextBox", "name": "DiscordWsUrl", "caption": "Discord Websocket URL" }, + { "type": "ValidationTextBox", "name": "Url", "caption": "Kofi Url" } + + ], + "actions": + [ + + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/Discord Kofi/module.json b/Discord Kofi/module.json new file mode 100644 index 0000000..b23b22d --- /dev/null +++ b/Discord Kofi/module.json @@ -0,0 +1,14 @@ +{ + "id": "{DDC385EB-AE56-685F-D265-85B5CE7F1FCE}", + "name": "Discord Kofi", + "type": 3, + "vendor": "Discord", + "aliases": + [ + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "DKM" +} \ No newline at end of file diff --git a/Discord Kofi/module.php b/Discord Kofi/module.php new file mode 100644 index 0000000..9b7e061 --- /dev/null +++ b/Discord Kofi/module.php @@ -0,0 +1,104 @@ +RegisterPropertyString("DiscordWsUrl",""); + $this->RegisterPropertyString("Url",""); + $this->RegisterPropertyString("Titel","Eine Nachricht von Kofi"); + } + + // Überschreibt die intere IPS_ApplyChanges($id) Funktion + public function ApplyChanges() { + // Diese Zeile nicht löschen + parent::ApplyChanges(); + } + /** + * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden. + * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt: + * + * DWM_SendMessage($id); + * + */ + public function SendMessage($from,$money,$timestamp,$message,$mail) { + + // Discord webhook URL + $webhookUrl = $this->ReadPropertyString("DiscordWsUrl"); + $Url = $this->ReadPropertyString("Url"); + $topic= $this->ReadPropertyString("Titel"); + // Data to send as JSON + $data = array( + "username" => $topic, + "avatar_url" => "https://storage.ko-fi.com/cdn/logomarkLogo.png", + "content" => "Du hast eine Spende erhalten", + "embeds" => array( + array( + "author" => array( + "name" => "Kofi", + "url" => $Url, + "icon_url" => "https://storage.ko-fi.com/cdn/logomarkLogo.png" + ), + "color" => 15258703, + "fields" => array( + array( + "name" => "Von:", + "value" => $from, + "inline" => true + ), + array( + "name" => "Betrag:", + "value" => $money, + "inline" => true + ), + array( + "name" => "Wann:", + "value" => $timestamp + ), + array( + "name" => "Nachricht:", + "value" => $message + ), + array( + "name" => "Mail:", + "value" => $mail + ) + ) + ) + ) + ); + // Encode the data as JSON + $jsonData = json_encode($data); + + // Initialize cURL session + $ch = curl_init($webhookUrl); + + // Set cURL options + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "Content-Type: application/json", + "Content-Length: " . strlen($jsonData) + )); + + // Execute the cURL session and capture the response + $response = curl_exec($ch); + + // Check for cURL errors + if (curl_errno($ch)) { + echo "cURL Error: " . curl_error($ch); + } + + // Close cURL session + curl_close($ch); + + // Display the response from the webhook + ///echo "Webhook Response: " . $response; + + + } +} +?> \ No newline at end of file