Search in sources :

Example 6 with IGuildChannel

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

the class Guild method setup.

/**
 * Sets up a guild with data from the gateway
 *
 * @param data
 *            The guild's data
 */
@Override
public void setup(GuildJSON data) {
    try {
        name = data.name;
        icon = data.icon != null ? data.icon : null;
        iconURL = icon != null ? Endpoints.guildIcon(getID(), icon) : null;
        ownerID = SnowflakeUtil.parse(data.owner_id);
        memberCount = data.member_count;
        voiceRegion = new VoiceRegion(data.region);
        splashHash = data.splash;
        if (data.roles.length > 0) {
            roles.clear();
            for (RoleJSON role : data.roles) {
                IRole r = gfac.buildRole(this, role);
                roles.put(r.getID(), r);
            }
        }
        if (data.members != null && data.members.length > 0) {
            members.clear();
            for (MemberJSON member : data.members) {
                IGuildMember m = gfac.buildMember(this, member);
                members.put(m.getID(), m);
            }
        }
        if (data.channels != null && data.channels.length > 0) {
            for (ChannelJSON channelData : data.channels) {
                IGuildChannel chan = (IGuildChannel) EntityRegistry.addChannel(channelData, getLoader(), this);
                if (chan instanceof IGuildTextChannel)
                    textChannels.put(chan.getID(), (IGuildTextChannel) chan);
                else if (chan instanceof IGuildVoiceChannel)
                    voiceChannels.put(chan.getID(), (IGuildVoiceChannel) chan);
            }
        }
        if (data.presences != null && data.presences.length > 0) {
            presences.clear();
            for (PresenceJSON presence : data.presences) {
                this.setPresence(presence);
            }
        }
        if (data.emojis != null && data.emojis.length > 0) {
            this.guildEmojis.clear();
            for (EmojiJSON e : data.emojis) {
                this.guildEmojis.put(SnowflakeUtil.parse(e.id), new GuildEmoji(e, this));
            }
        }
        if (data.voice_states != null && data.voice_states.length > 0) {
            this.rawStates.clear();
            for (VoiceStateJSON v : data.voice_states) {
                this.rawStates.put(SnowflakeUtil.parse(v.user_id), new VoiceState(v, this));
            }
        }
        this.available = data.unavailable == true ? false : true;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VoiceState(io.discloader.discloader.entity.voice.VoiceState) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IOException(java.io.IOException) GuildSyncException(io.discloader.discloader.common.exceptions.GuildSyncException) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) MissmatchException(io.discloader.discloader.common.exceptions.MissmatchException) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) RoleJSON(io.discloader.discloader.network.json.RoleJSON) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) VoiceRegion(io.discloader.discloader.entity.guild.VoiceRegion) IRole(io.discloader.discloader.entity.guild.IRole) VoiceStateJSON(io.discloader.discloader.network.json.VoiceStateJSON) IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PresenceJSON(io.discloader.discloader.network.json.PresenceJSON) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) MemberJSON(io.discloader.discloader.network.json.MemberJSON) EmojiJSON(io.discloader.discloader.network.json.EmojiJSON)

Example 7 with IGuildChannel

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

the class ChannelCategory method removeChannel.

@Override
public <T extends IGuildChannel> CompletableFuture<T> removeChannel(T channel) {
    CompletableFuture<T> future = new CompletableFuture<>();
    JSONObject settings = new JSONObject().put("parent_id", (String) null);
    loader.rest.request(Methods.PATCH, Endpoints.channel(channel.getID()), new RESTOptions(settings), ChannelJSON.class).thenAcceptAsync(data -> {
        @SuppressWarnings("unchecked") T newChannel = (T) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), guild, false);
        future.complete(newChannel);
    }).exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : Endpoints(io.discloader.discloader.network.util.Endpoints) Methods(io.discloader.discloader.network.util.Methods) IOverwrite(io.discloader.discloader.entity.IOverwrite) ChannelTypes(io.discloader.discloader.entity.channel.ChannelTypes) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) EntityBuilder(io.discloader.discloader.common.registry.EntityBuilder) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) SnowflakeUtil(io.discloader.discloader.entity.util.SnowflakeUtil) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) JSONObject(org.json.JSONObject) Map(java.util.Map) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IGuild(io.discloader.discloader.entity.guild.IGuild) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions)

Example 8 with IGuildChannel

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

the class ChannelCategory method createChannel.

@Override
public CompletableFuture<IGuildChannel> createChannel(String name, ChannelTypes type, IOverwrite... overwrites) {
    CompletableFuture<IGuildChannel> future = new CompletableFuture<>();
    // JSONObject data = new JSONObject().put("parent_id",
    // SnowflakeUtil.asString(this)).put("name", name).put("type", type.toInt()).;
    ChannelPayload data = new ChannelPayload(name, type, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildChannel channel = (IGuildChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                future.complete(channel);
        }
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload)

Example 9 with IGuildChannel

use of io.discloader.discloader.entity.channel.IGuildChannel 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 10 with IGuildChannel

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

Aggregations

IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)11 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)9 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 JSONObject (org.json.JSONObject)7 IGuild (io.discloader.discloader.entity.guild.IGuild)6 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)5 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)5 EntityBuilder (io.discloader.discloader.common.registry.EntityBuilder)5 IOverwrite (io.discloader.discloader.entity.IOverwrite)5 IChannelCategory (io.discloader.discloader.entity.channel.IChannelCategory)5 SnowflakeUtil (io.discloader.discloader.entity.util.SnowflakeUtil)5 Endpoints (io.discloader.discloader.network.util.Endpoints)5 Methods (io.discloader.discloader.network.util.Methods)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)4 IChannel (io.discloader.discloader.entity.channel.IChannel)4 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)4 IRole (io.discloader.discloader.entity.guild.IRole)4