Advertisement
kyroskoh

Twitch CustomAPI - Random Lick

May 7th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2. // Set names to lowercase for URL injection.
  3. $ToLower = strtolower($_GET["To"]);
  4. // Inject lowercase names to get correct capitalization of usernames.
  5. $ch = curl_init("https://api.twitch.tv/kraken/channels/" . $ToLower);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. $result = curl_exec($ch);
  8. curl_close($ch);
  9. // Decode the above JSON data.
  10. $ToCorrectName = json_decode($result, true);
  11. // No name was entered after the command.
  12. if (empty($_GET["To"]))
  13. {
  14.         echo 'Hey ' . htmlspecialchars($_GET["From"]) . ' to need to specify a user to direct the !give command towards!';
  15.         die();
  16. }
  17. // No such Twitch user exists, yet.
  18. if($ToCorrectName['display_name'] == null)
  19. {
  20.     echo 'Sorry, ' . htmlspecialchars($_GET["From"]) . ', ' . htmlspecialchars($_GET["To"]) . ' isn\'t a Twitch streamer!';
  21.     die();
  22. }
  23. // Array of places to lick.
  24. $Licks = array
  25. (
  26.     "the tongue!",
  27.     "their face!",
  28.     "the eye!",
  29.     "their hair!",
  30.     "their cheek!",
  31.     "their finger!",
  32.     "their elbow!",
  33.     "their nipple!",
  34.     "their hairy chest!",
  35.     "their groin! <3",
  36.     "their knee!",
  37.     "their booty hole! GROSS!",
  38.     "their thigh!",
  39.     "their foot!",
  40.     "their toes!"
  41. );
  42. // Count the array size, and return a ranodm entry from the array.
  43. $Lick = $Licks[mt_rand(0, count($Licks) - 1)];
  44. // Print the output.
  45. echo htmlspecialchars($_GET["From"]) . ' licks ' . $ToCorrectName['display_name'] . ' on ' . $Lick . ', lick lick';
  46. ?>
  47.  
  48. Example: Lick.php?From=Myself&To=TwitchUsername
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement