Search in sources :

Example 1 with ITextChannel

use of io.discloader.discloader.entity.channel.ITextChannel 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);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) IChannel(io.discloader.discloader.entity.channel.IChannel) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) ChannelUpdateEvent(io.discloader.discloader.common.event.channel.ChannelUpdateEvent) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IMessage(io.discloader.discloader.entity.message.IMessage) IGuild(io.discloader.discloader.entity.guild.IGuild) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)

Example 2 with ITextChannel

use of io.discloader.discloader.entity.channel.ITextChannel 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 3 with ITextChannel

use of io.discloader.discloader.entity.channel.ITextChannel 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 4 with ITextChannel

use of io.discloader.discloader.entity.channel.ITextChannel 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 5 with ITextChannel

use of io.discloader.discloader.entity.channel.ITextChannel 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)
        return;
    IMessage message = channel.getMessage(data.id);
    if (message == null)
        return;
    channel.getMessages().remove(message.getID());
    MessageDeleteEvent event = new MessageDeleteEvent(message);
    loader.emit(Events.MESSAGE_DELETE, event);
    loader.emit(event);
    if (channel.getType() == ChannelTypes.DM) {
        loader.emit(new PrivateMessageDeleteEvent(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) 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)

Aggregations

ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)7 IMessage (io.discloader.discloader.entity.message.IMessage)6 IUser (io.discloader.discloader.entity.user.IUser)3 MessageJSON (io.discloader.discloader.network.json.MessageJSON)3 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 ChannelUpdateEvent (io.discloader.discloader.common.event.channel.ChannelUpdateEvent)1 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)1 TypingStartEvent (io.discloader.discloader.common.event.channel.TypingStartEvent)1 GroupMessageUpdateEvent (io.discloader.discloader.common.event.message.GroupMessageUpdateEvent)1 GuildMessageCreateEvent (io.discloader.discloader.common.event.message.GuildMessageCreateEvent)1 GuildMessageDeleteEvent (io.discloader.discloader.common.event.message.GuildMessageDeleteEvent)1 GuildMessageUpdateEvent (io.discloader.discloader.common.event.message.GuildMessageUpdateEvent)1 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)1 MessageDeleteEvent (io.discloader.discloader.common.event.message.MessageDeleteEvent)1 MessageReactionAddEvent (io.discloader.discloader.common.event.message.MessageReactionAddEvent)1 MessageReactionRemoveEvent (io.discloader.discloader.common.event.message.MessageReactionRemoveEvent)1 MessageUpdateEvent (io.discloader.discloader.common.event.message.MessageUpdateEvent)1 PrivateMessageCreateEvent (io.discloader.discloader.common.event.message.PrivateMessageCreateEvent)1