use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method getPruneCount.
@Override
public CompletableFuture<Integer> getPruneCount(int days) {
CompletableFuture<Integer> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("days", days);
CompletableFuture<PruneCountJSON> cf = getLoader().rest.request(Methods.GET, Endpoints.guildPrune(getID()), new RESTOptions(payload), PruneCountJSON.class);
cf.thenAcceptAsync(data -> {
future.complete(Integer.valueOf(data.pruned));
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method kick.
@Override
public CompletableFuture<IGuildMember> kick(IGuildMember member, String reason) {
if (!isOwner() && getCurrentMember().getPermissions().hasPermission(Permissions.KICK_MEMBERS))
throw new PermissionsException("Insufficient Permissions");
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
CompletableFuture<Void> kickFuture = loader.rest.request(Methods.DELETE, Endpoints.guildMember(getID(), member.getID()), new RESTOptions(reason), Void.class);
kickFuture.thenAcceptAsync(n -> {
future.complete(member);
});
kickFuture.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method fetchMember.
public CompletableFuture<IGuildMember> fetchMember(long memberID) {
CompletableFuture<IGuildMember> future = new CompletableFuture<IGuildMember>();
CompletableFuture<MemberJSON> cf = loader.rest.request(Methods.GET, Endpoints.guildMember(getID(), memberID), new RESTOptions(), MemberJSON.class);
cf.thenAcceptAsync(data -> {
future.complete(addMember(data, true));
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method getAuditLog.
@Override
public CompletableFuture<IAuditLog> getAuditLog(int limit) {
CompletableFuture<IAuditLog> future = new CompletableFuture<>();
JSONObject params = new JSONObject().put("limit", limit);
CompletableFuture<AuditLogJSON> cf = loader.rest.request(Methods.GET, Endpoints.auditLogs(getID()), new RESTOptions(params), AuditLogJSON.class);
cf.thenAcceptAsync(al -> {
future.complete(new AuditLog(this, al));
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method edit.
public CompletableFuture<IGuild> edit(String name, String icon, IGuildVoiceChannel afkChannel) throws IOException {
if (!isOwner() && !getCurrentMember().getPermissions().hasPermission(Permissions.MANAGE_GUILD)) {
throw new PermissionsException();
}
CompletableFuture<IGuild> future = new CompletableFuture<>();
String base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(icon))));
JSONObject payload = new JSONObject().put("name", name).put("icon", base64);
CompletableFuture<GuildJSON> cf = getLoader().rest.request(Methods.PATCH, Endpoints.guild(getID()), new RESTOptions(payload), GuildJSON.class);
cf.thenAcceptAsync(guildJSON -> {
IGuild guild = clone();
guild.setup(guildJSON);
future.complete(guild);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations