· 6 years ago · Dec 12, 2019, 06:42 PM
1 }
2
3 public static String whatShouldIPlay(String userID) {
4 String api_key = BotManager.getInstance().SteamAPIKey;
5
6 try {
7 JSONParser parser = new JSONParser();
8 Object obj = parser.parse(
9 BotManager.getRemoteContent("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="
10 + api_key + "&steamid=" + userID + "&format=json&include_appinfo=1"));
11
12 JSONObject jsonObject = (JSONObject) obj;
13
14 JSONObject response = (JSONObject) (jsonObject.get("response"));
15 JSONArray games = (JSONArray) response.get("games");
16
17 if (games.size() > 0) {
18 int randomGame = (int) (Math.random() * games.size() - 1);
19 JSONObject index0 = (JSONObject) games.get(randomGame);
20 String randomGameName = (String) index0.get("name");
21 return randomGameName;
22 } else {
23 return "User has no games";
24
25 }
26
27 } catch (Exception ex) {
28 System.out.println("Failed to query Steam API");
29 return "Error querying API";
30 }
31 }
32
33 public static String krakenCreated_at(String channel) {
34 try {
35 JSONParser parser = new JSONParser();
36 Object obj = parser
37 .parse(BotManager.getRemoteContentTwitch("https://api.twitch.tv/kraken/streams/" + channel, 5));
38
39 JSONObject jsonObject = (JSONObject) obj;
40
41 JSONObject stream = (JSONObject) (jsonObject.get("stream"));
42 if (stream == null)
43 return "(offline)";
44
45 String viewers = (String) stream.get("created_at");
46 return viewers;
47 } catch (Exception ex) {
48 ex.printStackTrace();
49 return "(error)";
50 }
51
52 }
53
54 public static String steam(String userID, String retValues) {
55 String api_key = BotManager.getInstance().SteamAPIKey;
56
57 try {
58 JSONParser parser = new JSONParser();
59 Object obj = parser.parse(BotManager
60 .getRemoteContent("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?steamids="
61 + userID + "&key=" + api_key));
62
63 JSONObject jsonObject = (JSONObject) obj;
64
65 JSONObject response = (JSONObject) (jsonObject.get("response"));
66 JSONArray players = (JSONArray) response.get("players");
67
68 if (players.size() > 0) {
69 JSONObject index0 = (JSONObject) players.get(0);
70 String profileurl = (String) index0.get("profileurl");
71 String gameextrainfo = (String) index0.get("gameextrainfo");
72 String gameserverip = (String) index0.get("gameserverip");
73 String gameid = (String) index0.get("gameid");
74
75 if (retValues.equals("profile"))
76 return JSONUtil.shortenUrlTinyURL(profileurl);
77 else if (retValues.equals("game"))
78 return (gameextrainfo != null ? gameextrainfo : "(unavailable)");
79 else if (retValues.equals("server"))
80 return (gameserverip != null ? gameserverip : "(unavailable)");
81 else if (retValues.equals("store"))
82 return (gameid != null ? "http://store.steampowered.com/app/" + gameid : "(unavailable)");
83 else
84 return "Profile: " + JSONUtil.shortenUrlTinyURL(profileurl)
85 + (gameextrainfo != null ? ", Game: " + gameextrainfo : "")
86 + (gameserverip != null ? ", Server: " + gameserverip : "");
87
88 } else {
89 return "Error querying API";
90 }
91 } catch (Exception ex) {
92 System.out.println("Failed to query Steam API");
93 return "Error querying API";
94 }
95 }