use of io.discloader.discloader.common.event.channel.ChannelUpdateEvent 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