Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.76 KB | None | 0 0
  1. <?php
  2. //Post input from the website
  3. function isValidJSON($str) {
  4.    json_decode($str);
  5.    return json_last_error() == JSON_ERROR_NONE;
  6. }
  7.  
  8. $json_params = file_get_contents("php://input");
  9.  
  10. if (strlen($json_params) > 0 && isValidJSON($json_params)) {
  11.   $decoded_params = json_decode($json_params, JSON_UNESCAPED_SLASHES);
  12.   $data = $decoded_params;
  13. } else {
  14.   $data = "Not valid JSON";
  15. }
  16.  
  17. function fixLineBreak($var) {
  18.     $n = preg_replace("/\n/m", '\n', $var);
  19.     $r = preg_replace("/\r/m", '', $n);
  20.     return $r;
  21. }
  22.  
  23. //Timestamp
  24. date_default_timezone_set('UTC');
  25. $time1 = date("Y-m-d");
  26. $time2 = date("H:i:s");
  27. $time3 = date(v);
  28. $timestamp = $time1 ."T".$time2.".".$time3."Z";
  29.  
  30. //Build JSON
  31. $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"] .'"}]}]}';
  32.  
  33. //Communicate with Discord
  34. $url = "https://discordapp.com/api/webhooks/435427797213642753/WaUjROSLKhGlGNOg0OsM_8bhqDuSZGm576sUJdFgx_jLfycHYJchKR3H6fwX4xEaNWPl";
  35. $content = $discord_json;
  36.  
  37. $curl = curl_init($url);
  38. curl_setopt($curl, CURLOPT_HEADER, false);
  39. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  40. curl_setopt($curl, CURLOPT_HTTPHEADER,
  41.         array("Content-type: application/json"));
  42. curl_setopt($curl, CURLOPT_POST, true);
  43. curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
  44.  
  45. $json_response = curl_exec($curl);
  46.  
  47. $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  48.  
  49. if ( $status != 201 && $status != 204) {
  50.     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);
  51.     die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
  52.     } else {
  53.     echo "Embed sent successfully";
  54. }
  55.  
  56. curl_close($curl);
  57.  
  58. $response = json_decode($json_response, true);
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement