Search in sources :

Example 1 with IOverwrite

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);
}
Also used : IRole(io.discloader.discloader.entity.guild.IRole) IPermission(io.discloader.discloader.entity.IPermission) Permission(io.discloader.discloader.core.entity.Permission) IOverwrite(io.discloader.discloader.entity.IOverwrite)

Example 2 with IOverwrite

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;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) IChannel(io.discloader.discloader.entity.channel.IChannel) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) JSONArray(org.json.JSONArray) IOverwrite(io.discloader.discloader.entity.IOverwrite) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory)

Example 3 with IOverwrite

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;
}
Also used : Endpoints(io.discloader.discloader.network.util.Endpoints) IChannel(io.discloader.discloader.entity.channel.IChannel) Methods(io.discloader.discloader.network.util.Methods) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IPermission(io.discloader.discloader.entity.IPermission) ArrayList(java.util.ArrayList) SnowflakeUtil(io.discloader.discloader.entity.util.SnowflakeUtil) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) JSONObject(org.json.JSONObject) Map(java.util.Map) Permission(io.discloader.discloader.core.entity.Permission) IGuild(io.discloader.discloader.entity.guild.IGuild) EventListenerAdapter(io.discloader.discloader.common.event.EventListenerAdapter) FetchInvites(io.discloader.discloader.network.rest.actions.channel.FetchInvites) Role(io.discloader.discloader.core.entity.guild.Role) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) SetOverwrite(io.discloader.discloader.network.rest.actions.channel.SetOverwrite) CloseGuildChannel(io.discloader.discloader.network.rest.actions.channel.close.CloseGuildChannel) IOverwrite(io.discloader.discloader.entity.IOverwrite) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IRole(io.discloader.discloader.entity.guild.IRole) Permissions(io.discloader.discloader.entity.util.Permissions) EntityBuilder(io.discloader.discloader.common.registry.EntityBuilder) List(java.util.List) Guild(io.discloader.discloader.core.entity.guild.Guild) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IInvite(io.discloader.discloader.entity.invite.IInvite) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) Overwrite(io.discloader.discloader.core.entity.Overwrite) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) EntityRegistry(io.discloader.discloader.common.registry.EntityRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) IChannel(io.discloader.discloader.entity.channel.IChannel) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel)

Example 4 with IOverwrite

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;
}
Also used : Endpoints(io.discloader.discloader.network.util.Endpoints) IChannel(io.discloader.discloader.entity.channel.IChannel) Methods(io.discloader.discloader.network.util.Methods) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IPermission(io.discloader.discloader.entity.IPermission) ArrayList(java.util.ArrayList) SnowflakeUtil(io.discloader.discloader.entity.util.SnowflakeUtil) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) JSONObject(org.json.JSONObject) Map(java.util.Map) Permission(io.discloader.discloader.core.entity.Permission) IGuild(io.discloader.discloader.entity.guild.IGuild) EventListenerAdapter(io.discloader.discloader.common.event.EventListenerAdapter) FetchInvites(io.discloader.discloader.network.rest.actions.channel.FetchInvites) Role(io.discloader.discloader.core.entity.guild.Role) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) SetOverwrite(io.discloader.discloader.network.rest.actions.channel.SetOverwrite) CloseGuildChannel(io.discloader.discloader.network.rest.actions.channel.close.CloseGuildChannel) IOverwrite(io.discloader.discloader.entity.IOverwrite) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IRole(io.discloader.discloader.entity.guild.IRole) Permissions(io.discloader.discloader.entity.util.Permissions) EntityBuilder(io.discloader.discloader.common.registry.EntityBuilder) List(java.util.List) Guild(io.discloader.discloader.core.entity.guild.Guild) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IInvite(io.discloader.discloader.entity.invite.IInvite) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) Overwrite(io.discloader.discloader.core.entity.Overwrite) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) EntityRegistry(io.discloader.discloader.common.registry.EntityRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IOverwrite(io.discloader.discloader.entity.IOverwrite)

Example 5 with IOverwrite

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;
}
Also used : Endpoints(io.discloader.discloader.network.util.Endpoints) IChannel(io.discloader.discloader.entity.channel.IChannel) Methods(io.discloader.discloader.network.util.Methods) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IPermission(io.discloader.discloader.entity.IPermission) ArrayList(java.util.ArrayList) SnowflakeUtil(io.discloader.discloader.entity.util.SnowflakeUtil) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) JSONObject(org.json.JSONObject) Map(java.util.Map) Permission(io.discloader.discloader.core.entity.Permission) IGuild(io.discloader.discloader.entity.guild.IGuild) EventListenerAdapter(io.discloader.discloader.common.event.EventListenerAdapter) FetchInvites(io.discloader.discloader.network.rest.actions.channel.FetchInvites) Role(io.discloader.discloader.core.entity.guild.Role) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) SetOverwrite(io.discloader.discloader.network.rest.actions.channel.SetOverwrite) CloseGuildChannel(io.discloader.discloader.network.rest.actions.channel.close.CloseGuildChannel) IOverwrite(io.discloader.discloader.entity.IOverwrite) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IRole(io.discloader.discloader.entity.guild.IRole) Permissions(io.discloader.discloader.entity.util.Permissions) EntityBuilder(io.discloader.discloader.common.registry.EntityBuilder) List(java.util.List) Guild(io.discloader.discloader.core.entity.guild.Guild) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IInvite(io.discloader.discloader.entity.invite.IInvite) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) Overwrite(io.discloader.discloader.core.entity.Overwrite) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) EntityRegistry(io.discloader.discloader.common.registry.EntityRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IOverwrite(io.discloader.discloader.entity.IOverwrite) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IOverwrite (io.discloader.discloader.entity.IOverwrite)5 Permission (io.discloader.discloader.core.entity.Permission)4 IPermission (io.discloader.discloader.entity.IPermission)4 IChannel (io.discloader.discloader.entity.channel.IChannel)4 IChannelCategory (io.discloader.discloader.entity.channel.IChannelCategory)4 IRole (io.discloader.discloader.entity.guild.IRole)4 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)4 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 JSONObject (org.json.JSONObject)4 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)3 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)3 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)3 EntityBuilder (io.discloader.discloader.common.registry.EntityBuilder)3 EntityRegistry (io.discloader.discloader.common.registry.EntityRegistry)3 Overwrite (io.discloader.discloader.core.entity.Overwrite)3 Guild (io.discloader.discloader.core.entity.guild.Guild)3 Role (io.discloader.discloader.core.entity.guild.Role)3 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)3 IGuild (io.discloader.discloader.entity.guild.IGuild)3