Search in sources :

Example 1 with MessageUpdateEvent

use of io.discloader.discloader.common.event.message.MessageUpdateEvent in project DiscLoader by R3alCl0ud.

the class MessageUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    MessageJSON data = gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
    ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
    if (channel == null)
        return;
    IMessage oldMessage = channel.getMessage(data.id), message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
    MessageUpdateEvent event = new MessageUpdateEvent(message, oldMessage);
    loader.emit(Events.MESSAGE_UPDATE, event);
    loader.emit(event);
    if (message.getGuild() != null) {
        loader.emit(new GuildMessageUpdateEvent(message, oldMessage));
    } else if (channel.getType() == ChannelTypes.DM) {
        loader.emit(new PrivateMessageUpdateEvent(message, oldMessage));
    } else if (channel.getType() == ChannelTypes.GROUP) {
        loader.emit(new GroupMessageUpdateEvent(message, oldMessage));
    }
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage) PrivateMessageUpdateEvent(io.discloader.discloader.common.event.message.PrivateMessageUpdateEvent) MessageUpdateEvent(io.discloader.discloader.common.event.message.MessageUpdateEvent) PrivateMessageUpdateEvent(io.discloader.discloader.common.event.message.PrivateMessageUpdateEvent) GuildMessageUpdateEvent(io.discloader.discloader.common.event.message.GuildMessageUpdateEvent) GroupMessageUpdateEvent(io.discloader.discloader.common.event.message.GroupMessageUpdateEvent) GroupMessageUpdateEvent(io.discloader.discloader.common.event.message.GroupMessageUpdateEvent) GuildMessageUpdateEvent(io.discloader.discloader.common.event.message.GuildMessageUpdateEvent)

Aggregations

GroupMessageUpdateEvent (io.discloader.discloader.common.event.message.GroupMessageUpdateEvent)1 GuildMessageUpdateEvent (io.discloader.discloader.common.event.message.GuildMessageUpdateEvent)1 MessageUpdateEvent (io.discloader.discloader.common.event.message.MessageUpdateEvent)1 PrivateMessageUpdateEvent (io.discloader.discloader.common.event.message.PrivateMessageUpdateEvent)1 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)1 IMessage (io.discloader.discloader.entity.message.IMessage)1 MessageJSON (io.discloader.discloader.network.json.MessageJSON)1