Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. package yerobot;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.Reader;
  8. import java.net.URL;
  9. import java.nio.charset.Charset;
  10.  
  11. import org.jibble.pircbot.*;
  12. import org.json.JSONArray;
  13. import org.json.JSONException;
  14. import org.json.JSONObject;
  15.  
  16.  
  17.  
  18. public class TwitchStatus {
  19.  
  20.  
  21. public static JSONObject json;
  22. public static boolean isstreamlive;
  23.  
  24. public static String neuerfollower;
  25. public static String fname ;
  26.  
  27. public static int totalfollows;
  28. public static int viewercounter;
  29. public static int totalviews;
  30. public static JSONArray followerarray;
  31.  
  32.  
  33.  
  34.  
  35. ////////////////////////////////////////////////////////////////////////////////////
  36. // Twitch Live Checker
  37. ////////////////////////////////////////////////////////////////////////////////////
  38.  
  39. private static String readAll(Reader rd) throws IOException {
  40. StringBuilder sb = new StringBuilder();
  41. int cp;
  42. while ((cp = rd.read()) != -1) {
  43. sb.append((char) cp);
  44. }
  45. return sb.toString();
  46. }
  47.  
  48. public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
  49. InputStream is = new URL(url).openStream();
  50. try {
  51. BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
  52. String jsonText = readAll(rd);
  53. JSONObject json = new JSONObject(jsonText);
  54. return json;
  55. } finally {
  56. is.close();
  57. }
  58. }
  59.  
  60.  
  61.  
  62. public static void StreamChecker() throws IOException, JSONException {
  63. json = readJsonFromUrl("https://api.twitch.tv/kraken/streams/"+MyBot.ownerchannel);
  64.  
  65.  
  66. if(json.isNull("stream")) {
  67.  
  68. // offline //
  69.  
  70. isstreamlive = false;
  71.  
  72.  
  73. }else {
  74.  
  75. // online //
  76.  
  77. isstreamlive = true;
  78.  
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. ////////////////////////////////////////////////////////////////////////////////////
  89. // Twitch StreamStatus views/followers
  90. ////////////////////////////////////////////////////////////////////////////////////
  91.  
  92. private static String readAll2(Reader rd) throws IOException {
  93. StringBuilder sb = new StringBuilder();
  94. int cp;
  95. while ((cp = rd.read()) != -1) {
  96. sb.append((char) cp);
  97. }
  98. return sb.toString();
  99. }
  100.  
  101. public static JSONObject readJsonFromUrl2(String url) throws IOException, JSONException {
  102. InputStream is = new URL(url).openStream();
  103. try {
  104. BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
  105. String jsonText = readAll2(rd);
  106. JSONObject json = new JSONObject(jsonText);
  107. return json;
  108. } finally {
  109. is.close();
  110. }
  111. }
  112.  
  113. public static void Streamstatus() throws IOException, JSONException {
  114. json = readJsonFromUrl2("https://api.twitch.tv/kraken/streams/"+MyBot.ownerchannel);
  115.  
  116. viewercounter = json.getJSONObject("stream").getInt("viewers");
  117. totalviews = json.getJSONObject("stream").getJSONObject("channel").getInt("views");
  118. }
  119.  
  120.  
  121. ////////////////////////////////////////////////////////////////////////////////////
  122. // Twitch Follower Ticker
  123. ////////////////////////////////////////////////////////////////////////////////////
  124.  
  125. private String readAll4(Reader rd) throws IOException {
  126. StringBuilder sb = new StringBuilder();
  127. int cp;
  128. while ((cp = rd.read()) != -1) {
  129. sb.append((char) cp);
  130. }
  131. return sb.toString();
  132. }
  133.  
  134. public JSONObject readJsonFromUrl4(String url) throws IOException, JSONException {
  135. InputStream is = new URL(url).openStream();
  136. try {
  137. BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
  138. String jsonText = readAll4(rd);
  139. JSONObject json = new JSONObject(jsonText);
  140. return json;
  141. } finally {
  142. is.close();
  143. }
  144. }
  145.  
  146. public static void FollowerTicker() throws IOException, JSONException {
  147. json = readJsonFromUrl2("https://api.twitch.tv/kraken/channels/"+MyBot.ownerchannel+"/follows?direction=DESC&limit=100&offset="+MyBot.offsetvalue+"");
  148.  
  149. followerarray = json.getJSONArray("follows");
  150.  
  151. {
  152. JSONObject follower = followerarray.getJSONObject(0);
  153. neuerfollower = follower.getString("created_at");
  154. fname = follower.getJSONObject("user").getString("display_name");
  155. totalfollows = json.getInt("_total");
  156. }
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement