diff --git a/Discord Message/form.json b/Discord Message/form.json new file mode 100644 index 0000000..2f0a48c --- /dev/null +++ b/Discord Message/form.json @@ -0,0 +1,17 @@ +{ + "elements": + [ + { "type": "ValidationTextBox", "name": "DiscordWsUrl", "caption": "Discord Websocket URL" } + + ], + "actions": + [ + { "type": "ValidationTextBox", "name": "Title", "caption": "Title / User" }, + { "type": "ValidationTextBox", "name": "Message", "caption": "Message" }, + { "type": "Button", "label": "Send Message", "onClick": "DWM_SendMessage($id, $Title, $Message);" } + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/Discord Message/module.json b/Discord Message/module.json new file mode 100644 index 0000000..6f0cc86 --- /dev/null +++ b/Discord Message/module.json @@ -0,0 +1,14 @@ +{ + "id": "{FD72BA15-21B4-BB06-6CA5-E258CE6BF621}", + "name": "Discord Message", + "type": 3, + "vendor": "Discord", + "aliases": + [ + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "DWM" +} \ No newline at end of file diff --git a/Discord Message/module.php b/Discord Message/module.php new file mode 100644 index 0000000..0746ef6 --- /dev/null +++ b/Discord Message/module.php @@ -0,0 +1,67 @@ +RegisterPropertyString("DiscordWsUrl",""); + } + + // Ü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($topic,$message) { + + // Discord webhook URL + $webhookUrl = $this->ReadPropertyString("DiscordWsUrl"); + + // Data to send as JSON + $data = array( + "username" => $topic, + "content" => $message + ); + + // 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 diff --git a/library.json b/library.json new file mode 100644 index 0000000..a99c9ea --- /dev/null +++ b/library.json @@ -0,0 +1,13 @@ +{ + "id": "{7E872C9C-51B1-0ABF-9B05-6C90C5FA545D}", + "author": "J.H. Artworks", + "name": "Discord Websocket", + "url": "https://jh-artworks.com", + "compatibility": { + "version": "6.0", + "date": 1491343200 + }, + "version": "1.0", + "build": 0, + "date": 0 +} \ No newline at end of file