Search in sources :

Example 1 with IChannel

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

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

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

the class ChannelCreate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IChannel channel = EntityRegistry.addChannel(data, loader, guild);
    ChannelCreateEvent event = new ChannelCreateEvent(channel);
    loader.emit(Events.CHANNEL_CREATE, event);
    loader.emit(event);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IChannel(io.discloader.discloader.entity.channel.IChannel) ChannelCreateEvent(io.discloader.discloader.common.event.channel.ChannelCreateEvent) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 4 with IChannel

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

the class ChannelDelete method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
    IGuild guild = null;
    IChannel channel = null;
    if (data.guild_id != null) {
        guild = EntityRegistry.getGuildByID(data.guild_id);
        channel = EntityRegistry.addChannel(data, loader, guild);
    } else {
        channel = EntityRegistry.addChannel(data, loader);
    }
    switch(channel.getType()) {
        case TEXT:
            guild.getTextChannels().remove(channel.getID());
            break;
        case VOICE:
            guild.getVoiceChannels().remove(channel.getID());
            break;
        default:
            EntityRegistry.removeChannel(channel);
            break;
    }
    ChannelDeleteEvent event = new ChannelDeleteEvent(channel);
    loader.emit(Events.CHANNEL_DELETE, event);
    loader.emit(event);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IChannel(io.discloader.discloader.entity.channel.IChannel) ChannelDeleteEvent(io.discloader.discloader.common.event.channel.ChannelDeleteEvent) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 5 with IChannel

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

the class ChannelUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
    IGuild guild = null;
    IChannel oldChannel = EntityRegistry.getChannelByID(data.id);
    IChannel channel = null;
    if (data.guild_id != null) {
        guild = EntityRegistry.getGuildByID(data.guild_id);
    }
    channel = EntityRegistry.addChannel(data, loader, guild);
    if (oldChannel instanceof ITextChannel) {
        ITextChannel oitc = (ITextChannel) oldChannel, itc = (ITextChannel) channel;
        for (IMessage message : oitc.getMessages().values()) {
            itc.getMessages().put(message.getID(), message);
        }
    }
    ChannelUpdateEvent event = new ChannelUpdateEvent(channel, oldChannel);
    if (channel instanceof IGuildChannel && oldChannel instanceof IGuildChannel) {
        loader.emit(new GuildChannelUpdateEvent((IGuildChannel) channel, (IGuildChannel) oldChannel));
    }
    loader.emit(Events.CHANNEL_UPDATE, event);
    loader.emit(event);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) IChannel(io.discloader.discloader.entity.channel.IChannel) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) ChannelUpdateEvent(io.discloader.discloader.common.event.channel.ChannelUpdateEvent) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IMessage(io.discloader.discloader.entity.message.IMessage) IGuild(io.discloader.discloader.entity.guild.IGuild) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)

Aggregations

IChannel (io.discloader.discloader.entity.channel.IChannel)6 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)6 IGuild (io.discloader.discloader.entity.guild.IGuild)4 IChannelCategory (io.discloader.discloader.entity.channel.IChannelCategory)3 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 JSONObject (org.json.JSONObject)3 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)2 IOverwrite (io.discloader.discloader.entity.IOverwrite)2 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)2 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)1 ChannelCreateEvent (io.discloader.discloader.common.event.channel.ChannelCreateEvent)1 ChannelDeleteEvent (io.discloader.discloader.common.event.channel.ChannelDeleteEvent)1 ChannelUpdateEvent (io.discloader.discloader.common.event.channel.ChannelUpdateEvent)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