Search in sources :

Example 1 with GroupMessageCreateEvent

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

the class MessageCreate method handle.

@Override
public void handle(SocketPacket packet) {
    MessageJSON data = this.gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
    try {
        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(channelID);
        if (channel == null)
            return;
        IMessage message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
        channel.getMessages().put(message.getID(), message);
        if (channel.isTyping(message.getAuthor())) {
            channel.getTyping().remove(message.getAuthor().getID());
        }
        MessageCreateEvent event = new MessageCreateEvent(message);
        loader.emit(event);
        if (channel.getType() == ChannelTypes.TEXT) {
            loader.emit(event = new GuildMessageCreateEvent(message));
        } else if (channel.getType() == ChannelTypes.DM) {
            loader.emit(event = new PrivateMessageCreateEvent(message));
        } else if (channel.getType() == ChannelTypes.GROUP) {
            loader.emit(event = new GroupMessageCreateEvent(message));
        }
        CommandHandler.handleMessageCreate(event);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) GroupMessageCreateEvent(io.discloader.discloader.common.event.message.GroupMessageCreateEvent) GroupMessageCreateEvent(io.discloader.discloader.common.event.message.GroupMessageCreateEvent) PrivateMessageCreateEvent(io.discloader.discloader.common.event.message.PrivateMessageCreateEvent) MessageCreateEvent(io.discloader.discloader.common.event.message.MessageCreateEvent) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage) PrivateMessageCreateEvent(io.discloader.discloader.common.event.message.PrivateMessageCreateEvent) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent)

Aggregations

GroupMessageCreateEvent (io.discloader.discloader.common.event.message.GroupMessageCreateEvent)1 GuildMessageCreateEvent (io.discloader.discloader.common.event.message.GuildMessageCreateEvent)1 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)1 PrivateMessageCreateEvent (io.discloader.discloader.common.event.message.PrivateMessageCreateEvent)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