use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method createCategory.
@Override
public CompletableFuture<IChannelCategory> createCategory(String name) {
CompletableFuture<IChannelCategory> future = new CompletableFuture<>();
JSONObject chanSet = new JSONObject().put("name", name).put("type", 4);
loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(chanSet), ChannelJSON.class).thenAcceptAsync(d -> {
IChannel channel = EntityBuilder.getChannelFactory().buildChannel(d, loader, this, false);
if (channel instanceof IChannelCategory)
future.complete((IChannelCategory) channel);
});
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(IAuditLogEntry before) {
CompletableFuture<IAuditLog> future = new CompletableFuture<>();
JSONObject params = new JSONObject().put("before", SnowflakeUtil.asString(before));
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 getVoiceRegions.
@Override
public CompletableFuture<List<VoiceRegion>> getVoiceRegions() {
CompletableFuture<List<VoiceRegion>> future = new CompletableFuture<List<VoiceRegion>>();
CompletableFuture<VoiceRegionJSON[]> cf = getLoader().rest.request(Methods.GET, Endpoints.guildRegions(getID()), new RESTOptions(), VoiceRegionJSON[].class);
cf.thenAcceptAsync(regions -> {
List<VoiceRegion> rgs = new ArrayList<>();
for (VoiceRegionJSON region : regions) {
rgs.add(new VoiceRegion(region));
}
future.complete(rgs);
});
return future;
}
use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.
the class Guild method createEmoji.
@Override
public CompletableFuture<IGuildEmoji> createEmoji(String name, String image, IRole... roles) {
CompletableFuture<IGuildEmoji> future = new CompletableFuture<>();
String base64 = null;
try {
base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(image))));
} catch (IOException e) {
e.printStackTrace();
}
String[] rids = new String[roles.length];
for (int i = 0; i < rids.length; i++) {
rids[i] = SnowflakeUtil.asString(roles[i]);
}
CreateEmoji ce = new CreateEmoji(name, base64, rids);
CompletableFuture<EmojiJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildEmojis(getID()), new RESTOptions(ce), EmojiJSON.class);
cf.thenAcceptAsync(ed -> {
future.complete(new GuildEmoji(ed, this));
});
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 createCategory.
@Override
public CompletableFuture<IChannelCategory> createCategory(String name, IOverwrite... overwrites) {
CompletableFuture<IChannelCategory> future = new CompletableFuture<>();
JSONArray ows = new JSONArray();
for (IOverwrite ow : overwrites) {
ows.put(ow);
}
JSONObject chanSet = new JSONObject().put("name", name).put("type", 4).put("permission_overwrites", ows);
loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(chanSet), ChannelJSON.class).thenAcceptAsync(d -> {
IChannel channel = EntityBuilder.getChannelFactory().buildChannel(d, loader, this, false);
if (channel instanceof IChannelCategory)
future.complete((IChannelCategory) channel);
});
return future;
}
Aggregations