Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package yerobot;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.Reader;
- import java.net.URL;
- import java.nio.charset.Charset;
- import org.jibble.pircbot.*;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class TwitchStatus {
- public static JSONObject json;
- public static boolean isstreamlive;
- public static String neuerfollower;
- public static String fname ;
- public static int totalfollows;
- public static int viewercounter;
- public static int totalviews;
- public static JSONArray followerarray;
- ////////////////////////////////////////////////////////////////////////////////////
- // Twitch Live Checker
- ////////////////////////////////////////////////////////////////////////////////////
- private static String readAll(Reader rd) throws IOException {
- StringBuilder sb = new StringBuilder();
- int cp;
- while ((cp = rd.read()) != -1) {
- sb.append((char) cp);
- }
- return sb.toString();
- }
- public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
- InputStream is = new URL(url).openStream();
- try {
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
- String jsonText = readAll(rd);
- JSONObject json = new JSONObject(jsonText);
- return json;
- } finally {
- is.close();
- }
- }
- public static void StreamChecker() throws IOException, JSONException {
- json = readJsonFromUrl("https://api.twitch.tv/kraken/streams/"+MyBot.ownerchannel);
- if(json.isNull("stream")) {
- // offline //
- isstreamlive = false;
- }else {
- // online //
- isstreamlive = true;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- // Twitch StreamStatus views/followers
- ////////////////////////////////////////////////////////////////////////////////////
- private static String readAll2(Reader rd) throws IOException {
- StringBuilder sb = new StringBuilder();
- int cp;
- while ((cp = rd.read()) != -1) {
- sb.append((char) cp);
- }
- return sb.toString();
- }
- public static JSONObject readJsonFromUrl2(String url) throws IOException, JSONException {
- InputStream is = new URL(url).openStream();
- try {
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
- String jsonText = readAll2(rd);
- JSONObject json = new JSONObject(jsonText);
- return json;
- } finally {
- is.close();
- }
- }
- public static void Streamstatus() throws IOException, JSONException {
- json = readJsonFromUrl2("https://api.twitch.tv/kraken/streams/"+MyBot.ownerchannel);
- viewercounter = json.getJSONObject("stream").getInt("viewers");
- totalviews = json.getJSONObject("stream").getJSONObject("channel").getInt("views");
- }
- ////////////////////////////////////////////////////////////////////////////////////
- // Twitch Follower Ticker
- ////////////////////////////////////////////////////////////////////////////////////
- private String readAll4(Reader rd) throws IOException {
- StringBuilder sb = new StringBuilder();
- int cp;
- while ((cp = rd.read()) != -1) {
- sb.append((char) cp);
- }
- return sb.toString();
- }
- public JSONObject readJsonFromUrl4(String url) throws IOException, JSONException {
- InputStream is = new URL(url).openStream();
- try {
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
- String jsonText = readAll4(rd);
- JSONObject json = new JSONObject(jsonText);
- return json;
- } finally {
- is.close();
- }
- }
- public static void FollowerTicker() throws IOException, JSONException {
- json = readJsonFromUrl2("https://api.twitch.tv/kraken/channels/"+MyBot.ownerchannel+"/follows?direction=DESC&limit=100&offset="+MyBot.offsetvalue+"");
- followerarray = json.getJSONArray("follows");
- {
- JSONObject follower = followerarray.getJSONObject(0);
- neuerfollower = follower.getString("created_at");
- fname = follower.getJSONObject("user").getString("display_name");
- totalfollows = json.getInt("_total");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement