use of com.sx4.bot.entities.info.SteamFreeGame in project Sx4 by sx4-discord-bot.
the class FreeGameManager method ensureSteamFreeGames.
public void ensureSteamFreeGames() {
this.steamExecutor.scheduleAtFixedRate(() -> {
Request resultRequest = new Request.Builder().url("https://store.steampowered.com/search/?maxprice=free&specials=1&cc=gb").addHeader("Accept-Language", "en").build();
this.bot.getHttpClient().newCall(resultRequest).enqueue((HttpCallback) resultResponse -> {
org.jsoup.nodes.Document resultsDocument = Jsoup.parse(resultResponse.body().string());
Element results = resultsDocument.getElementById("search_resultsRows");
if (results == null) {
return;
}
List<CompletableFuture<SteamFreeGame>> futures = new ArrayList<>();
for (Element result : results.children()) {
Element discount = result.getElementsByClass("col search_discount responsive_secondrow").first();
if (!discount.text().equals("-100%")) {
continue;
}
int id = Integer.parseInt(result.attr("data-ds-appid"));
Request gameRequest = new Request.Builder().url("https://store.steampowered.com/app/" + id + "?cc=gb").addHeader("Accept-Language", "en").build();
CompletableFuture<SteamFreeGame> future = new CompletableFuture<>();
this.bot.getHttpClient().newCall(gameRequest).enqueue((HttpCallback) gameResponse -> {
org.jsoup.nodes.Document document = Jsoup.parse(gameResponse.body().string());
Element content = document.getElementsByClass("page_content_ctn").first();
SteamFreeGame game = SteamFreeGame.fromData(id, content);
if (this.isAnnounced(game)) {
future.complete(null);
return;
}
future.complete(game);
});
futures.add(future);
}
FutureUtility.allOf(futures, Objects::nonNull).whenComplete((games, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception) || games.isEmpty()) {
return;
}
this.sendFreeGameNotifications(games).whenComplete(MongoDatabase.exceptionally());
});
});
}, 0, 30, TimeUnit.MINUTES);
}
Aggregations