Advertisement
kyroskoh

Twitch CustomAPI - Random Love

May 7th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <?php
  2. // Set the percentage at the chances of "love".
  3. $LoveValue = mt_rand (0,100);
  4. // Set names to lowercase for URL injection & string comparison.
  5. $ToLower = strtolower($_GET["To"]);
  6. $FromLower = strtolower($_GET["From"]);
  7. $BroadcasterLower = strtolower($_GET["Broadcaster"]);
  8. // Inject lowercase names to get correct capitalization of usernames.
  9. $ch = curl_init("https://api.twitch.tv/kraken/channels/" . $ToLower);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  11. $result = curl_exec($ch);
  12. curl_close($ch);
  13. // Decode the above JSON data.
  14. $ToCorrectName = json_decode($result, true);
  15. // No name was entered after the command.
  16. if (empty($_GET["To"]))
  17. {
  18.     echo 'Hey ' . htmlspecialchars($_GET["From"]) . ' if you wish to know your chances at love with someone, you must tell me who you wish to have me calculate your chances at love with!';
  19.     die();
  20. }
  21. // No such Twitch user exists, yet.
  22. if($ToCorrectName['display_name'] == null)
  23. {
  24.     echo 'Sorry, ' . htmlspecialchars($_GET["From"]) . ', ' . htmlspecialchars($_GET["To"]) . ' isn\'t a Twitch streamer!';
  25.     die();
  26. }
  27. // Tried to check the chances at love with the broadcaster.
  28. if ($BroadcasterLower == $ToLower)
  29. {
  30.     echo 'There is a 110% chance at <3! ' . htmlspecialchars($_GET["Broadcaster"]) . ' loves everyone who watches the stream!';
  31.     die();
  32. }
  33. // Someone loves themself a little too much.
  34. if ($ToLower == $FromLower)
  35. {
  36.     echo $ToCorrectName['display_name'] . ', please... Kappa';
  37.     die();
  38. }
  39. // Can't kill a bot...
  40. if ($ToLower == 'nightbot' || $ToLower == 'wizebot' || $ToLower == 'moobot')
  41. {
  42.     echo 'Silly homosapian, bots can\'t know real love bleedPurple';
  43.     die();
  44. }
  45.  
  46. // Display first part
  47. echo 'There is a ' . $LoveValue . '% chance of <3 between ' . htmlspecialchars($_GET["From"]) . ' and ' . $ToCorrectName['display_name'] . '! ';
  48. // Show "love advice".
  49.  
  50. if (0 <= $LoveValue && $LoveValue <= 10)
  51. {
  52.     echo 'I wouldn\'t count on it lasting. ;(';
  53. }
  54. if (11 <= $LoveValue && $LoveValue <= 20)
  55. {
  56.     echo 'There\'s a slim possibility, but doesn\'t look too promising. :(';
  57. }
  58. if (21 <= $LoveValue && $LoveValue <= 30)
  59. {
  60.     echo 'Alot of work will be needed, but there\'s a possibility.';
  61. }
  62. if (31 <= $LoveValue && $LoveValue <= 40)
  63. {
  64.     echo 'A successful relationship is possible, but you both have to work on it.';
  65. }
  66. if (41 <= $LoveValue && $LoveValue <= 50)
  67. {
  68.     echo 'A relationship is very well possible.';
  69. }
  70. if (51 <= $LoveValue && $LoveValue <= 60)
  71. {
  72.     echo 'The relationship has a reasonable chance of working out, but on the other hand, it might not.';
  73. }
  74. if (61 <= $LoveValue && $LoveValue <= 70)
  75. {
  76.     echo 'Your relationship may suffer good and bad times. If things might not be working out as you would like them to, do not hesitate to talk about it.';
  77. }
  78. if (71 <= $LoveValue && $LoveValue <= 80)
  79. {
  80.     echo 'Spend time together, talk with each other.';
  81. }
  82. if (81 <= $LoveValue && $LoveValue <= 90)
  83. {
  84.     echo 'A relationship has a very good chance of being successful! <3';
  85. }
  86. if (91 <= $LoveValue && $LoveValue <= 100)
  87. {
  88.     echo 'Better put a ring on it right away! <3<3';
  89. }
  90. ?>
  91.  
  92. Example: Love.php?Broadcaster=TwitchBroadcaster&From=Myself&To=TwitchUsername
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement