Search in sources :

Example 1 with GroupMessageDeleteEvent

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

the class MessageDelete method handle.

@Override
public void handle(SocketPacket packet) {
    MessageJSON data = this.gson.fromJson(this.gson.toJson(packet.d), MessageJSON.class);
    long channelID = SnowflakeUtil.parse(data.channel_id);
    ITextChannel channel = EntityRegistry.getTextChannelByID(channelID);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(channelID);
    if (channel == null)
        channel = EntityRegistry.getGroupChannelByID(data.channel_id);
    if (channel == null)
        return;
    IMessage message = channel.getMessage(data.id);
    if (message == null)
        return;
    channel.getMessages().remove(message.getID());
    MessageDeleteEvent event = new MessageDeleteEvent(message);
    loader.emit(event);
    if (channel.getType() == ChannelTypes.DM) {
        loader.emit(new PrivateMessageDeleteEvent(message));
    } else if (channel.getType() == ChannelTypes.GROUP) {
        loader.emit(new GroupMessageDeleteEvent(message));
    }
    if (message.getGuild() != null) {
        loader.emit(new GuildMessageDeleteEvent(message));
    }
}
Also used : PrivateMessageDeleteEvent(io.discloader.discloader.common.event.message.PrivateMessageDeleteEvent) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) GroupMessageDeleteEvent(io.discloader.discloader.common.event.message.GroupMessageDeleteEvent) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage) GuildMessageDeleteEvent(io.discloader.discloader.common.event.message.GuildMessageDeleteEvent) PrivateMessageDeleteEvent(io.discloader.discloader.common.event.message.PrivateMessageDeleteEvent) GuildMessageDeleteEvent(io.discloader.discloader.common.event.message.GuildMessageDeleteEvent) MessageDeleteEvent(io.discloader.discloader.common.event.message.MessageDeleteEvent) GroupMessageDeleteEvent(io.discloader.discloader.common.event.message.GroupMessageDeleteEvent)

Aggregations

GroupMessageDeleteEvent (io.discloader.discloader.common.event.message.GroupMessageDeleteEvent)1 GuildMessageDeleteEvent (io.discloader.discloader.common.event.message.GuildMessageDeleteEvent)1 MessageDeleteEvent (io.discloader.discloader.common.event.message.MessageDeleteEvent)1 PrivateMessageDeleteEvent (io.discloader.discloader.common.event.message.PrivateMessageDeleteEvent)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