Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Post input from the website
- function isValidJSON($str) {
- json_decode($str);
- return json_last_error() == JSON_ERROR_NONE;
- }
- $json_params = file_get_contents("php://input");
- if (strlen($json_params) > 0 && isValidJSON($json_params)) {
- $decoded_params = json_decode($json_params, JSON_UNESCAPED_SLASHES);
- $data = $decoded_params;
- } else {
- $data = "Not valid JSON";
- }
- function fixLineBreak($var) {
- $n = preg_replace("/\n/m", '\n', $var);
- $r = preg_replace("/\r/m", '', $n);
- return $r;
- }
- //Timestamp
- date_default_timezone_set('UTC');
- $time1 = date("Y-m-d");
- $time2 = date("H:i:s");
- $time3 = date(v);
- $timestamp = $time1 ."T".$time2.".".$time3."Z";
- //Build JSON
- $discord_json = '{"content":"__**WE HAVE RECIEVED A NEW APPLICATION FOR:**__ '. $data["team"] .' ","embeds":[{"color":42751,"author":{"name":"'. $data["character"] .', a '. $data["race"] .' '. $data["spec"] .' '. $data["class"] .'","url":"'. $data["wlogs"] .'","icon_url":"https://i.imgur.com/FK8T1nQ.png"},"timestamp":"'. $timestamp .'","footer":{"icon_url":"https://cdn.discordapp.com/embed/avatars/0.png","text":"Powered by Salty"},"fields":[{"name":"Age:","value":"'. $data["age"] .'"},{"name":"Nationality:","value":"'. $data["nationality"] .'"},{"name":"Current Artifact level?:","value":"'. $data["artifact"] .'"},{"name":"Previous guilds:","value":"'. fixLineBreak($data["previousguild"]) .'"},{"name":"Experience in WoW:","value":"'. fixLineBreak($data["experience"]) .'"},{"name":"Who am I?:","value":"'. fixLineBreak($data["yourself"]) .'"},{"name":"Extra info:","value":"'. fixLineBreak($data["extra"]) .' "},{"name":"Contact","value":"'. $data["bnet"] .'"}]}]}';
- //Communicate with Discord
- $url = "https://discordapp.com/api/webhooks/435427797213642753/WaUjROSLKhGlGNOg0OsM_8bhqDuSZGm576sUJdFgx_jLfycHYJchKR3H6fwX4xEaNWPl";
- $content = $discord_json;
- $curl = curl_init($url);
- curl_setopt($curl, CURLOPT_HEADER, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HTTPHEADER,
- array("Content-type: application/json"));
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
- $json_response = curl_exec($curl);
- $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if ( $status != 201 && $status != 204) {
- mail("salty@salty.dk","Curl Status","Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl) . " \n " . $discord_json);
- die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
- } else {
- echo "Embed sent successfully";
- }
- curl_close($curl);
- $response = json_decode($json_response, true);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement