use of chatty.util.UrlRequest in project chatty by chatty.
the class NewsDialog method requestNews.
/**
* Requests the announcements from the server.
*/
private void requestNews(final boolean openIfUnread) {
news.setText("Loading..");
latestNewsTimestamp = 0;
lastRequested = System.currentTimeMillis();
refreshButton.setEnabled(false);
UrlRequest request = new UrlRequest(Chatty.DEBUG ? NEWS_URL_TEST : NEWS_URL);
request.async((result, responseCode) -> {
SwingUtilities.invokeLater(() -> {
if (responseCode == 200) {
int unread = setNews(result);
if (openIfUnread && unread > 0) {
showDialog();
}
} else {
news.setText("Error loading news. (" + responseCode + ")");
}
refreshButton.setEnabled(true);
});
});
}
use of chatty.util.UrlRequest in project chatty by chatty.
the class FrankerFaceZ method requestBotNames.
/**
* Request and parse FFZ bot names.
*/
public void requestBotNames() {
UrlRequest request = new UrlRequest("https://api.frankerfacez.com/v1/badge/bot");
request.setLabel("FFZ Bots");
request.async((result, responseCode) -> {
if (result != null && responseCode == 200) {
Set<String> botNames = FrankerFaceZParsing.getBotNames(result);
LOGGER.info("[FFZ Bots] Found " + botNames.size() + " names");
listener.botNamesReceived(botNames);
}
});
}
use of chatty.util.UrlRequest in project chatty by chatty.
the class WebsocketManager method fetchEmoteSet.
/**
* Get the emotes from a specific emoteset, useable in the given room.
*
* @param room The channel the emotes should be useable in
* @param emoteset The FFZ emoteset to fetch
* @return A set of emotes or an empty set if an error occured
*/
private Set<Emoticon> fetchEmoteSet(String room, int emoteset) {
UrlRequest r = new UrlRequest("https://api.frankerfacez.com/v1/set/" + emoteset);
FullResult result = r.sync();
if (result.getResult() != null) {
Set<Emoticon> emotes = FrankerFaceZParsing.parseSetEmotes(result.getResult(), Emoticon.SubType.EVENT, room);
return emotes;
}
return new HashSet<>();
}
use of chatty.util.UrlRequest in project chatty by chatty.
the class UpdateMessage method loadChangelog.
/**
* Loads the changelog if not already successfully loaded.
*/
private void loadChangelog() {
if (changelogLoaded) {
return;
}
changelog.setText("Loading..");
UrlRequest request = new UrlRequest(CHANGELOG_URL);
request.async((result, responseCode) -> {
if (responseCode == 200) {
changelog.setText(result);
changelogLoaded = true;
} else {
changelog.setText("Error loading changelog.");
}
});
}
use of chatty.util.UrlRequest in project chatty by chatty.
the class FrankerFaceZ method request.
/**
* Issue a request of the given type and stream.
*
* <p>
* The URL which is used for the request is build from the paramters. Only
* requests each URL once, unless {@code forcedUpdate} is true. Always
* prevents the same URL from being requested twice at the same time.</p>
*
* <p>This is not safe to be called unsynchronized, because of the way
* check the URL for being already requested/pending is done.</p>
*
* @param type The type of request
* @param stream The stream, can be {@code null} if not needed for this type
* @param forcedUpdate Whether to request even if already requested before
*/
private void request(final Type type, final String stream, boolean forcedUpdate) {
final String url = getUrl(type, stream);
if (requestPending.contains(url) || (alreadyRequested.contains(url) && !forcedUpdate)) {
return;
}
alreadyRequested.add(url);
requestPending.add(url);
// Create request and run it in a seperate thread
UrlRequest request = new UrlRequest();
request.setLabel("FFZ");
request.setUrl(url);
request.async((result, responseCode) -> {
requestPending.remove(url);
parseResult(type, stream, result);
});
}
Aggregations