Search in sources :

Example 1 with ReactionJSON

use of io.discloader.discloader.network.json.ReactionJSON 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 2 with ReactionJSON

use of io.discloader.discloader.network.json.ReactionJSON in project DiscLoader by R3alCl0ud.

the class Message method setup.

@Override
public void setup(MessageJSON data) {
    mentions = new Mentions(this, data.mentions, data.mention_roles, data.mention_everyone);
    timestamp = data.timestamp;
    edited_timestamp = data.edited_timestamp;
    tts = data.tts;
    content = data.content;
    nonce = data.nonce;
    if (data.embeds != null) {
        for (EmbedJSON em : data.embeds) {
            embeds.add(new MessageEmbed(em));
        }
    }
    type = data.type;
    if (data.reactions != null) {
        for (ReactionJSON r : data.reactions) {
            reactions.add(new Reaction(r, this));
        }
    }
    if (data.activity != null) {
        activity = new MessageActivity(data.activity);
    }
    if (data.application != null) {
        application = new MessageApplication(data.application);
    }
}
Also used : IMentions(io.discloader.discloader.entity.message.IMentions) EmbedJSON(io.discloader.discloader.network.json.EmbedJSON) IMessageEmbed(io.discloader.discloader.entity.message.IMessageEmbed) MessageEmbed(io.discloader.discloader.core.entity.message.embed.MessageEmbed) IMessageActivity(io.discloader.discloader.entity.message.IMessageActivity) IMessageApplication(io.discloader.discloader.entity.message.IMessageApplication) ReactionJSON(io.discloader.discloader.network.json.ReactionJSON) CreateReaction(io.discloader.discloader.network.rest.actions.message.CreateReaction) IReaction(io.discloader.discloader.entity.message.IReaction) DeleteReaction(io.discloader.discloader.network.rest.actions.message.DeleteReaction)

Example 3 with ReactionJSON

use of io.discloader.discloader.network.json.ReactionJSON in project DiscLoader by R3alCl0ud.

the class ReactionAdd 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);
    message.getReactions().add(reaction);
    loader.emit(new MessageReactionAddEvent(message, reaction, user));
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageReactionAddEvent(io.discloader.discloader.common.event.message.MessageReactionAddEvent) 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)

Aggregations

IReaction (io.discloader.discloader.entity.message.IReaction)3 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)3 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)2 IMessage (io.discloader.discloader.entity.message.IMessage)2 IUser (io.discloader.discloader.entity.user.IUser)2 MessageReactionAddEvent (io.discloader.discloader.common.event.message.MessageReactionAddEvent)1 MessageReactionRemoveEvent (io.discloader.discloader.common.event.message.MessageReactionRemoveEvent)1 MessageEmbed (io.discloader.discloader.core.entity.message.embed.MessageEmbed)1 IMentions (io.discloader.discloader.entity.message.IMentions)1 IMessageActivity (io.discloader.discloader.entity.message.IMessageActivity)1 IMessageApplication (io.discloader.discloader.entity.message.IMessageApplication)1 IMessageEmbed (io.discloader.discloader.entity.message.IMessageEmbed)1 EmbedJSON (io.discloader.discloader.network.json.EmbedJSON)1 CreateReaction (io.discloader.discloader.network.rest.actions.message.CreateReaction)1 DeleteReaction (io.discloader.discloader.network.rest.actions.message.DeleteReaction)1