-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlmgtfy.php
48 lines (34 loc) · 1.4 KB
/
lmgtfy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
$user_agent = "lmgtfy/1.0 (https://github.com/kenibarwick/lmgtfy-slack; [email protected])";
$command = $_POST['command'];
$search = $_POST['text'];
$token = $_POST['token'];
if($token != 'dMhNdMFR1atYtBLjIZ8iP3ty'){
$msg = "The token for the slash command doesn't match. Check your script.";
die($msg);
echo $msg;
}
$longUrl = "http://lmgtfy.com/?q=".$search;
$postData = array('longUrl' => $longUrl);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyAqk5yBchMhkzTX8Q8_6Ryi-C8FmqwDAhU');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
// Change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
if($ch_response === FALSE){
# lmgtfy.org could not be reached
$reply = "The world is dying as Google could not be reached.";
} else {
// $reply = "Have a look here for your answer ".$response_array["$url_to_check"];
$reply = "You'll find your answer here: *<".$json->id.">.*";
}
echo $reply;
?>