use of io.discloader.discloader.common.exceptions.PermissionsException in project DiscLoader by R3alCl0ud.
the class TextChannel method edit.
@Override
public CompletableFuture<IGuildTextChannel> edit(String name, String topic) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
if (name.length() < 2 || name.length() > 100) {
throw new RuntimeException("Name.length() out of bounds [2-100]");
}
if (topic.length() > 1024) {
throw new RuntimeException("Topic.length() out of bounds [" + topic.length() + " > 1024]");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("name", sanitizeChannelName(name)).put("topic", topic);
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
cf.thenAcceptAsync(data -> {
IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
future.complete(channel);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.common.exceptions.PermissionsException in project DiscLoader by R3alCl0ud.
the class TextChannel method setNSFW.
@Override
public CompletableFuture<IGuildTextChannel> setNSFW(boolean nsfw) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("nsfw", nsfw);
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
cf.thenAcceptAsync(data -> {
IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
future.complete(channel);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.common.exceptions.PermissionsException in project DiscLoader by R3alCl0ud.
the class Guild method beginPrune.
@Override
public CompletableFuture<Integer> beginPrune(int days) {
if (!getCurrentMember().getPermissions().hasPermission(Permissions.KICK_MEMBERS))
throw new PermissionsException("Pruning members requires the 'KICK_MEMBERS' permission");
CompletableFuture<Integer> future = new CompletableFuture<>();
loader.rest.request(Methods.POST, Endpoints.guildPrune(getID()), new RESTOptions(), Integer.class).thenAcceptAsync(pruned -> {
future.complete(pruned);
});
return future;
}
use of io.discloader.discloader.common.exceptions.PermissionsException 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.common.exceptions.PermissionsException 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