Advertisement
kyroskoh

Twitch CustomAPI - Random Give

May 7th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 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 items to give.
  24. $Items = array
  25. (
  26.     "a beer! Cheers!",
  27.     "free food!",
  28.     "fellatio! Kinky... ",
  29.     "a cookie!",
  30.     "a kiss!",
  31.     "anal! Well, this just became awkward...",
  32.     "a hug!",
  33.     "an Ambien! Sleep tight Kappa",
  34.     "$20! The ummm... check is in the mail...",
  35.     "$10! The ummm... check is in the mail...",
  36.     "$5! The ummm... check is in the mail...",
  37.     "$1! The ummm... check is in the mail...",
  38.     "$50! The ummm... check is in the mail...",
  39.     "$100! The ummm... check is in the mail...",
  40.     "sex!",
  41.     "a doughnut!",
  42.     "a car!",
  43.     "a Cheeto!",
  44.     "a slice of pizza!",
  45.     "a pear!",
  46.     "a kiwi!",
  47.     "an iPod!",
  48.     "an iPhone!",
  49.     "an iPad",
  50.     "an Android!",
  51.     "their own Batmobile!",
  52.     "a monkey!",
  53.     "a dog!",
  54.     "a cat!",
  55.     "a pet fish",
  56.     "a stinky fish! Icky!",
  57.     "a dead dog! Gross!",
  58.     "a dead cat! Gross!",
  59.     "moldy pizza! Thanks...",
  60.     "a VD! You shouldn't have, really...",
  61.     "an apple!",
  62.     "a Snicker1!",
  63.     "a Reeses!",
  64.     "anal!",
  65.     "an Oreo!",
  66.     "100 viewers!"
  67. );
  68. // Count the array size, and return a ranodm entry from the array.
  69. $Item = $Items[mt_rand(0, count($Items) - 1)];
  70. // Print the output.
  71. echo htmlspecialchars($_GET["From"]) . ' gives ' . $ToCorrectName['display_name'] . ' ' . $Item;
  72. ?>
  73.  
  74. Example: Give.php?From=Myself&To=TwitchUsername
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement