Search in sources :

Example 1 with IChannelCategory

use of io.discloader.discloader.entity.channel.IChannelCategory 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;
}
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) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory)

Example 2 with IChannelCategory

use of io.discloader.discloader.entity.channel.IChannelCategory 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 IChannelCategory

use of io.discloader.discloader.entity.channel.IChannelCategory in project DiscLoader by R3alCl0ud.

the class GuildChannel method setCategory.

@Override
public CompletableFuture<IGuildChannel> setCategory(IChannelCategory category) {
    CompletableFuture<IGuildChannel> future = new CompletableFuture<>();
    JSONObject settings = new JSONObject().put("parent_id", SnowflakeUtil.asString(category));
    loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(settings), ChannelJSON.class).thenAcceptAsync(data -> {
        IGuildChannel newChannel = (IGuildChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
        future.complete(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) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel)

Aggregations

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