use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.
the class GayCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", endless = true, acceptEmpty = true) @ImageUrl String imageUrl) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("gay")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.
the class HotCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", endless = true, acceptEmpty = true) @ImageUrl String imageUrl) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("hot")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.
the class ResizeCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url") @ImageUrl String imageUrl, @Argument(value = "width") @Limit(min = 0, max = 5000) double width, @Argument(value = "height") @Limit(min = 0, max = 5000) @DefaultNumber(1) double height) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("resize")).addQuery("w", width).addQuery("h", height).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
ImageUtility.getImageMessage(event, response, (body, error) -> {
if (error == ImageError.INVALID_QUERY_VALUE) {
return event.replyFailure(body.getString("message"));
}
return null;
}).queue();
});
}
use of com.sx4.bot.http.HttpCallback in project Sx4 by sx4-discord-bot.
the class SkinPortManager method retrieveCSRFData.
public void retrieveCSRFData() {
Request request = new Request.Builder().url("https://skinport.com/api/data").build();
this.bot.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
List<String> cookies = response.headers("Set-Cookie");
String cookie = cookies.get(0);
this.cookie = cookie.substring(0, cookie.indexOf(';'));
Document data = Document.parse(response.body().string());
this.csrf = data.getString("csrf");
this.currency = data.getString("currency");
this.currencies = data.get("rates", Document.class);
});
}
use of com.sx4.bot.http.HttpCallback 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