use of io.discloader.discloader.entity.IOverwrite in project DiscLoader by R3alCl0ud.
the class GuildChannel method permissionsOf.
@Override
public IPermission permissionsOf(IGuildMember member) {
long raw = 0;
if (getGuild().isOwner(member))
return new Permission(member, this, 2146958463);
for (IRole role : member.getRoles()) {
if (role != null) {
raw |= role.getPermissions().toLong();
}
}
for (IOverwrite overwrite : overwritesOf(member)) {
raw |= overwrite.getAllowed();
raw &= ~overwrite.getDenied();
}
return new Permission(member, this, raw);
}
use of io.discloader.discloader.entity.IOverwrite 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;
}
use of io.discloader.discloader.entity.IOverwrite in project DiscLoader by R3alCl0ud.
the class GuildChannel method edit.
@Override
public CompletableFuture<? extends IGuildChannel> edit(String name, int position, boolean nsfw, IOverwrite... overwrites) throws PermissionsException {
CompletableFuture<IGuildChannel> future = new CompletableFuture<>();
JSONObject settings = new JSONObject().put("name", name).put("position", position).put("nsfw", nsfw).put("permission_overwrites", overwrites);
loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(settings), ChannelJSON.class).thenAcceptAsync(data -> {
IChannel newChannel = EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
if (newChannel instanceof IGuildChannel)
future.complete((IGuildChannel) newChannel);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.entity.IOverwrite in project DiscLoader by R3alCl0ud.
the class GuildChannel method deleteOverwrite.
// @Override
// public CompletableFuture<IGuildChannel> clone() {
// return guild.createTextChannel(name);
// }
@Override
public CompletableFuture<IOverwrite> deleteOverwrite(IOverwrite overwrite) {
CompletableFuture<IOverwrite> future = new CompletableFuture<>();
loader.rest.request(Methods.DELETE, Endpoints.channelOverwrite(getID(), overwrite.getID()), new RESTOptions(), Void.class).thenAcceptAsync(n -> {
future.complete(overwrite);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.entity.IOverwrite in project DiscLoader by R3alCl0ud.
the class GuildChannel method deleteOverwrites.
@Override
public CompletableFuture<List<IOverwrite>> deleteOverwrites(IOverwrite... overwrites) {
CompletableFuture<List<IOverwrite>> future = new CompletableFuture<>();
List<IOverwrite> keep = new ArrayList<>(), removed = new ArrayList<>();
for (IOverwrite ow : this.overwrites.values()) keep.add(ow);
for (IOverwrite ow : overwrites) {
if (this.overwrites.containsKey(ow.getID())) {
keep.remove(this.overwrites.get(ow.getID()));
removed.add(this.overwrites.get(ow.getID()));
}
}
JSONObject props = new JSONObject().put("permission_overwrites", keep);
loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(props), ChannelJSON.class).thenAcceptAsync(data -> {
future.complete(removed);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations