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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations