use of lib.JSON.JSONObject in project Botnak by Gocnak.
the class FaceManager method handleEmoteSet.
public static void handleEmoteSet(String emotes) {
if (checkedEmoteSets)
return;
ThreadEngine.submit(() -> {
try {
checkedEmoteSets = true;
String line = APIRequests.Twitch.getEmoteSet(emotes);
if (!line.isEmpty()) {
User main = Settings.channelManager.getUser(Settings.accountManager.getUserAccount().getName(), true);
JSONObject init = new JSONObject(line);
String[] keys = emotes.split(",");
JSONObject emote_sets = init.getJSONObject("emoticon_sets");
for (String s : keys) {
JSONArray set = emote_sets.getJSONArray(s);
for (int i = 0; i < set.length(); i++) {
JSONObject emote = set.getJSONObject(i);
int ID = emote.getInt("id");
main.addEmote(ID);
if (doneWithTwitchFaces) {
if (twitchFaceMap.get(ID) == null) {
downloadEmote(ID);
}
}
}
}
}
} catch (Exception e) {
GUIMain.log("FaceManager: Failed to download EmoteSets!");
checkedEmoteSets = false;
}
});
}
use of lib.JSON.JSONObject in project Botnak by Gocnak.
the class FaceManager method buildMap.
/**
* Builds the giant all-containing Twitch Face map.
*/
public static void buildMap() {
try {
// Load twitch faces
String line = APIRequests.Twitch.getAllEmotes();
if (!line.isEmpty()) {
try {
JSONObject init = new JSONObject(line);
JSONArray emotes = init.getJSONArray("emoticons");
for (int i = 0; i < emotes.length(); i++) {
JSONObject emote = emotes.getJSONObject(i);
int ID = emote.getInt("id");
if (twitchFaceMap.get(ID) != null)
continue;
String regex = emote.getString("code").replaceAll("\\\\<\\\\;", "\\<").replaceAll("\\\\>\\\\;", "\\>");
String URL = "http://static-cdn.jtvnw.net/emoticons/v1/" + ID + "/1.0";
onlineTwitchFaces.put(ID, new TwitchFace(regex, URL, true));
}
} catch (Exception e) {
GUIMain.log("Failed to load online Twitch faces, is the API endpoint down?");
}
}
} catch (Exception e) {
GUIMain.log(e);
}
}
use of lib.JSON.JSONObject in project Botnak by Gocnak.
the class UserManager method beat.
@Override
public void beat() {
beating = true;
String[] channels = Settings.channelManager.getChannelNames();
URL url;
for (String chan : channels) {
String chanOut = chan.substring(1);
GUIViewerList list = GUIMain.viewerLists.get(chanOut);
if (list != null) {
try {
url = new URL("http://tmi.twitch.tv/group/user/" + chan.substring(1) + "/chatters");
String line = Utils.createAndParseBufferedReader(url.openStream());
if (!line.isEmpty()) {
final Enumeration<TreePath> beforePaths = list.beforePaths();
final int beforeScroll = list.beforeScroll();
JSONObject site = new JSONObject(line);
JSONObject chatters = site.getJSONObject("chatters");
JSONArray mods = chatters.getJSONArray("moderators");
readAndUpdate(mods, list, GUIViewerList.ViewerType.MOD);
JSONArray staff = chatters.getJSONArray("staff");
readAndUpdate(staff, list, GUIViewerList.ViewerType.STAFF);
JSONArray admins = chatters.getJSONArray("admins");
readAndUpdate(admins, list, GUIViewerList.ViewerType.ADMIN);
JSONArray global_mods = chatters.getJSONArray("global_mods");
readAndUpdate(global_mods, list, GUIViewerList.ViewerType.GLOBAL_MOD);
JSONArray viewers = chatters.getJSONArray("viewers");
readAndUpdate(viewers, list, GUIViewerList.ViewerType.VIEWER);
EventQueue.invokeLater(() -> list.updateRoot(beforePaths, beforeScroll));
Thread.sleep(2000);
}
} catch (Exception e) {
GUIMain.log(e);
}
}
}
}
use of lib.JSON.JSONObject in project Botnak by Gocnak.
the class DonationManager method scanInitialDonations.
public void scanInitialDonations(int passesCompleted) {
String url = "https://streamtip.com/api/tips?client_id=" + getClientID() + "&access_token=" + getAccessCode() + "&limit=100&direction=asc";
try {
String offset = "&offset=" + String.valueOf(100 * passesCompleted);
String line = Utils.createAndParseBufferedReader(new URL(url + offset).openStream());
if (!line.isEmpty()) {
JSONObject outerShell = new JSONObject(line);
int status = outerShell.getInt("status");
int count = outerShell.getInt("_count");
if (count > 0) {
if (status == 200) {
//ensure there's no problem with the site
JSONArray tipsArray = outerShell.getJSONArray("tips");
for (int i = 0; i < tipsArray.length(); i++) {
JSONObject tip = tipsArray.getJSONObject(i);
if (lastDonation != null) {
if (lastDonation.getDonationID().equals(tip.getString("_id"))) {
continue;
}
}
addDonation(tip, true);
//we're simulating a local donation here to not spam the chat with all the donations
}
scanInitialDonations(passesCompleted + 1);
} else {
GUIMain.log("Failed to scan initial donations due to an error on Streamtip!");
}
} else {
//finished!
GUIMain.log("Successfully scanned initial donations!");
}
}
} catch (Exception e) {
GUIMain.log(e);
}
}
use of lib.JSON.JSONObject in project Botnak by Gocnak.
the class DonationManager method checkDonations.
public void checkDonations(boolean single) {
int limit = (single ? 5 : 100);
String url = "https://streamtip.com/api/tips?client_id=" + getClientID() + "&access_token=" + getAccessCode() + "&limit=" + limit;
try {
String line = Utils.createAndParseBufferedReader(new URL(url).openStream());
if (!line.isEmpty()) {
JSONObject outerShell = new JSONObject(line);
int status = outerShell.getInt("status");
int count = outerShell.getInt("_count");
if (status == 200) {
//ensure there's no problem with the site
JSONArray tipsArray = outerShell.getJSONArray("tips");
for (int i = (single ? tipsArray.length() - 1 : count - 1); i > -1; i--) {
JSONObject tip = tipsArray.getJSONObject(i);
try {
Currency c = Currency.getInstance(tip.getString("currencyCode"));
getCurrencyFormat().setCurrency(c);
} catch (Exception e) {
GUIMain.log("Unknown currency code: " + tip.getString("currencyCode"));
getCurrencyFormat().setCurrency(Currency.getInstance("USD"));
}
if (lastDonation != null) {
if (lastDonation.getDonationID().equals(tip.getString("_id"))) {
continue;
}
}
addDonation(tip, false);
}
}
}
} catch (Exception e) {
GUIMain.log(e);
}
}
Aggregations