use of de.foryasee.httprequest.RequestHeader in project Rubicon by Rubicon-Bot.
the class CommandJoke method execute.
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
HttpRequestBuilder request = new HttpRequestBuilder("https://icanhazdadjoke.com/", RequestType.GET);
RequestHeader header = new RequestHeader();
header.addField("Accept", "application/json");
header.addField("User-Agent", "RubiconBot (https://github.com/Rubicon-Bot/Rubicon)");
request.setRequestHeader(header);
try {
RequestResponse response = request.sendRequest();
JSONObject json = (JSONObject) new JSONParser().parse(response.getResponseMessage());
SafeMessage.sendMessage(parsedCommandInvocation.getTextChannel(), new EmbedBuilder().setTitle("Joke").setDescription((String) json.get("joke")).setColor(Colors.COLOR_SECONDARY).build());
} catch (Exception e) {
e.printStackTrace();
SafeMessage.sendMessage(parsedCommandInvocation.getTextChannel(), EmbedUtil.error("Error 404", "No joke was found!").build(), 30);
}
return null;
}
Aggregations