Search in sources :

Example 6 with HttpRequestBuilder

use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.

the class MemberJoinRequestImpl method build.

@Override
public HttpRequestBuilder build() {
    HttpRequestBuilder request = new HttpRequestBuilder(WebpanelData.BASE_URL, RequestType.GET);
    request.addParameter("type", WebpanelData.MEMBER_JOIN.getKey());
    request.addParameter("guildid", guild.getId());
    request.addParameter("guildname", guild.getName());
    return request;
}
Also used : HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder)

Example 7 with HttpRequestBuilder

use of de.foryasee.httprequest.HttpRequestBuilder 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;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) JSONObject(org.json.simple.JSONObject) RequestHeader(de.foryasee.httprequest.RequestHeader) JSONParser(org.json.simple.parser.JSONParser) HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder) RequestResponse(de.foryasee.httprequest.RequestResponse)

Example 8 with HttpRequestBuilder

use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.

the class CommandVideo method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation invocation, UserPermissions userPermissions) {
    String[] args = invocation.getArgs();
    if (args.length < 1)
        createHelpMessage(invocation);
    String query = invocation.getMessage().getContentDisplay().replace(invocation.getPrefix() + invocation.getCommandInvocation(), "");
    HttpRequestBuilder request = new HttpRequestBuilder("https://www.googleapis.com/youtube/v3/search", RequestType.GET);
    request.addParameter("type", "video");
    request.addParameter("q", query);
    request.addParameter("part", "snippet");
    request.addParameter("key", Info.GOOGLE_TOKEN);
    try {
        RequestResponse response = request.sendRequest();
        JSONObject json = (JSONObject) new JSONParser().parse(response.getResponseMessage());
        JSONArray data = (JSONArray) json.get("items");
        JSONObject snippet = (JSONObject) ((JSONObject) data.get(0)).get("snippet");
        JSONObject id = (JSONObject) ((JSONObject) data.get(0)).get("id");
        JSONObject thumbnails = (JSONObject) snippet.get("thumbnails");
        EmbedBuilder message = new EmbedBuilder().setColor(Colors.COLOR_PRIMARY).setTitle((String) snippet.get("title"), "https://youtu.be/" + id.get("videoId")).setAuthor(invocation.getAuthor().getName(), null, invocation.getAuthor().getAvatarUrl()).setTimestamp(new Date().toInstant()).setThumbnail((String) ((JSONObject) thumbnails.get("default")).get("url")).addField("Video Description", (String) snippet.get("description"), false).addField("Channel Name", (String) snippet.get("channelTitle"), true);
        invocation.getTextChannel().sendMessage(message.build()).queue();
    } catch (Exception e) {
        e.printStackTrace();
        return EmbedUtil.message(EmbedUtil.error("Error!", "Found no Video."));
    }
    return null;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder) RequestResponse(de.foryasee.httprequest.RequestResponse) Date(java.util.Date)

Example 9 with HttpRequestBuilder

use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.

the class CommandGiphy method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    String[] args = parsedCommandInvocation.getArgs();
    if (args.length < 1) {
        return createHelpMessage();
    }
    String query = parsedCommandInvocation.getMessage().getContentDisplay().replace(parsedCommandInvocation.getPrefix() + parsedCommandInvocation.getCommandInvocation(), "");
    HttpRequestBuilder request = new HttpRequestBuilder("https://api.giphy.com/v1/gifs/search", RequestType.GET);
    request.addParameter("api_key", Info.GIPHY_TOKEN);
    request.addParameter("q", query);
    try {
        RequestResponse response = request.sendRequest();
        JSONObject json = (JSONObject) new JSONParser().parse(response.getResponseMessage());
        JSONArray data = (JSONArray) json.get("data");
        parsedCommandInvocation.getTextChannel().sendMessage((String) ((JSONObject) data.get(0)).get("url")).queue();
    } catch (Exception e) {
        return EmbedUtil.message(EmbedUtil.error("Error!", "Found no gif."));
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder) RequestResponse(de.foryasee.httprequest.RequestResponse)

Example 10 with HttpRequestBuilder

use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.

the class MojangUtil method fetchName.

private String fetchName(String playername) {
    HttpRequestBuilder request = new HttpRequestBuilder("https://api.mojang.com/users/profiles/minecraft/" + playername, RequestType.GET);
    RequestResponse response = null;
    try {
        response = request.sendRequest();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (response.getResponseCode() != 200)
        return null;
    JSONObject json = null;
    try {
        json = (JSONObject) parser.parse(response.getResponseMessage());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return json.get("name").toString();
}
Also used : JSONObject(org.json.simple.JSONObject) HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder) RequestResponse(de.foryasee.httprequest.RequestResponse) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException)

Aggregations

HttpRequestBuilder (de.foryasee.httprequest.HttpRequestBuilder)15 RequestResponse (de.foryasee.httprequest.RequestResponse)10 JSONObject (org.json.simple.JSONObject)7 JSONParser (org.json.simple.parser.JSONParser)5 ParseException (org.json.simple.parser.ParseException)4 JSONArray (org.json.simple.JSONArray)3 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 RequestHeader (de.foryasee.httprequest.RequestHeader)1 Date (java.util.Date)1 HTTPException (javax.xml.ws.http.HTTPException)1 JSONObject (org.json.JSONObject)1