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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations