Search in sources :

Example 6 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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)
            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(DLUtil.Events.MESSAGE_CREATE, event);
        loader.emit(event);
        if (channel.getType() == ChannelTypes.TEXT) {
            GuildMessageCreateEvent event2 = new GuildMessageCreateEvent(message);
            loader.emit("GuildMessageCreate", event2);
            loader.emit(event2);
        } else if (channel.getType() == ChannelTypes.DM) {
            PrivateMessageCreateEvent event2 = new PrivateMessageCreateEvent(message);
            loader.emit(DLUtil.Events.PRIVATE_MESSAGE_CREATE, event2);
            loader.emit(event2);
        }
        CommandHandler.handleMessageCreate(event);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) 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)

Example 7 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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)

Example 8 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class ReactionRemove method handle.

public void handle(SocketPacket packet) {
    ReactionJSON data = gson.fromJson(gson.toJson(packet.d), ReactionJSON.class);
    IUser user = EntityRegistry.getUserByID(data.user_id);
    ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
    if (channel == null)
        return;
    IMessage message = channel.getMessage(data.message_id);
    if (message == null || user == null)
        return;
    IReaction reaction = new Reaction(data, message);
    for (IReaction r : message.getReactions()) {
        if (r.getEmoji().toString().equals(reaction.toString()))
            reaction = r;
    }
    message.getReactions().remove(reaction);
    loader.emit(new MessageReactionRemoveEvent(message, reaction, user));
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageReactionRemoveEvent(io.discloader.discloader.common.event.message.MessageReactionRemoveEvent) IMessage(io.discloader.discloader.entity.message.IMessage) IUser(io.discloader.discloader.entity.user.IUser) IReaction(io.discloader.discloader.entity.message.IReaction) ReactionJSON(io.discloader.discloader.network.json.ReactionJSON) Reaction(io.discloader.discloader.core.entity.message.Reaction) IReaction(io.discloader.discloader.entity.message.IReaction)

Example 9 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class FetchMessages method complete.

@Override
public void complete(String s, Throwable ex) {
    if (ex != null) {
        future.completeExceptionally(ex);
        return;
    } else {
        MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
        HashMap<Long, IMessage> messages = new HashMap<>();
        for (MessageJSON m : data) {
            IMessage message = new Message<>(channel, m);
            channel.getMessages().put(message.getID(), message);
            messages.put(message.getID(), message);
        }
        future.complete(messages);
    }
}
Also used : IMessage(io.discloader.discloader.entity.message.IMessage) Message(io.discloader.discloader.core.entity.message.Message) MessageJSON(io.discloader.discloader.network.json.MessageJSON) HashMap(java.util.HashMap) IMessage(io.discloader.discloader.entity.message.IMessage)

Example 10 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class PinnedMessages method complete.

@Override
public void complete(String s, Throwable ex) {
    if (ex != null) {
        future.completeExceptionally(ex);
        return;
    } else {
        MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
        HashMap<Long, IMessage> messages = new HashMap<>();
        for (MessageJSON m : data) {
            IMessage message = new Message<T>(channel, m);
            channel.getMessages().put(message.getID(), message);
            messages.put(message.getID(), message);
        }
        future.complete(messages);
    }
}
Also used : IMessage(io.discloader.discloader.entity.message.IMessage) Message(io.discloader.discloader.core.entity.message.Message) MessageJSON(io.discloader.discloader.network.json.MessageJSON) HashMap(java.util.HashMap) IMessage(io.discloader.discloader.entity.message.IMessage)

Aggregations

IMessage (io.discloader.discloader.entity.message.IMessage)23 MessageJSON (io.discloader.discloader.network.json.MessageJSON)12 CompletableFuture (java.util.concurrent.CompletableFuture)10 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)8 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)6 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)6 File (java.io.File)5 Message (io.discloader.discloader.core.entity.message.Message)3 Attachment (io.discloader.discloader.entity.sendable.Attachment)3 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)2 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)2 RichEmbed (io.discloader.discloader.core.entity.RichEmbed)2 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)2 IPrivateChannel (io.discloader.discloader.entity.channel.IPrivateChannel)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 IUser (io.discloader.discloader.entity.user.IUser)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 HashMap (java.util.HashMap)2 Lists (com.google.common.collect.Lists)1