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, int position) {
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]");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("name", sanitizeChannelName(name)).put("position", position);
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 createVoiceChannel.
@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name, int bitRate, int userLimit, IChannelCategory category, IOverwrite... overwrites) {
CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
if (!hasPermission(Permissions.MANAGE_CHANNELS)) {
PermissionsException ex = new PermissionsException("Insufficient Permissions");
future.completeExceptionally(ex);
// return early
return future;
}
// normalize
bitRate = Math.max(8, Math.min(96, bitRate)) * 1000;
// normalize
userLimit = Math.max(0, Math.min(99, userLimit));
ChannelPayload data = new ChannelPayload(name, bitRate, userLimit, overwrites);
if (category != null && getChannelCategoryByID(category.getID()) != null) {
data.setParent(category);
}
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
cf.thenAcceptAsync(channelJSON -> {
if (channelJSON != null) {
IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), this, false);
if (channel != null)
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 ban.
@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member, String reason) throws PermissionsException {
if (!hasPermission(Permissions.BAN_MEMBERS))
throw new PermissionsException("");
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(reason), Void.class).thenAcceptAsync(action -> {
future.complete(member);
});
return future;
}
use of io.discloader.discloader.common.exceptions.PermissionsException in project DiscLoader by R3alCl0ud.
the class Guild method ban.
@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member) {
if (!hasPermission(Permissions.BAN_MEMBERS))
throw new PermissionsException("");
CompletableFuture<IGuildMember> future = new CompletableFuture<>();
loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(), Void.class).thenAcceptAsync(action -> {
future.complete(member);
});
return future;
}
use of io.discloader.discloader.common.exceptions.PermissionsException in project DiscLoader by R3alCl0ud.
the class GuildEmoji method setRoles.
@Override
public CompletableFuture<IGuildEmoji> setRoles(IRole... roles) {
if (!guild.hasPermission(Permissions.MANAGE_EMOJIS)) {
throw new PermissionsException("Insufficient Permissions: \"MANAGE_EMOJIS\" is required to use this endpoint");
}
CompletableFuture<IGuildEmoji> future = new CompletableFuture<>();
String[] payload = new String[roles.length];
for (int i = 0; i < roles.length; i++) {
payload[i] = SnowflakeUtil.asString(roles[i]);
}
IEventListener el = new EventListenerAdapter() {
@Override
public void GuildEmojiUpdate(GuildEmojiUpdateEvent event) {
if (getID() == event.getEmoji().getID()) {
future.complete(event.getEmoji());
getLoader().removeEventListener(this);
}
}
};
getLoader().addEventListener(el).rest.request(Methods.PATCH, Endpoints.guildEmoji(getGuild().getID(), getID()), new RESTOptions(payload), EmojiJSON.class).exceptionally(ex -> {
future.completeExceptionally(ex);
getLoader().removeEventListener(el);
return null;
});
return future;
}
Aggregations