Search in sources :

Example 6 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class GuildBanRemove method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    GuildMemberRemoveJSON data = gson.fromJson(d, GuildMemberRemoveJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IUser user = EntityRegistry.addUser(data.user);
    GuildBanRemoveEvent event = new GuildBanRemoveEvent(guild, user);
    loader.emit(DLUtil.Events.GUILD_BAN_REMOVE, event);
    loader.emit(event);
}
Also used : GuildMemberRemoveJSON(io.discloader.discloader.network.json.GuildMemberRemoveJSON) GuildBanRemoveEvent(io.discloader.discloader.common.event.guild.GuildBanRemoveEvent) IUser(io.discloader.discloader.entity.user.IUser) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 7 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class PresenceUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    PresenceJSON data = this.gson.fromJson(gson.toJson(packet.d), PresenceJSON.class);
    IUser user = EntityRegistry.getUserByID(data.user.id);
    if (user == null) {
        if (data.user.username != null) {
            user = EntityRegistry.addUser(data.user);
        } else {
            return;
        }
    }
    IUser oldUser = new User(user);
    user.setup(data.user);
    if (!user.equals(oldUser)) {
        UserUpdateEvent event = new UserUpdateEvent(user, oldUser);
        loader.emit(DLUtil.Events.USER_UPDATE, event);
        loader.emit(event);
    }
    IGuild guild = data.guild_id == null ? null : EntityRegistry.getGuildByID(data.guild_id);
    if (guild != null) {
        IGuildMember oldMember = guild.getMember(user.getID()), member;
        if (oldMember == null && !data.status.equalsIgnoreCase("offline")) {
            member = guild.addMember(user, data.roles, false, false, data.nick, false);
            loader.emit(DLUtil.Events.GUILD_MEMBER_AVAILABLE, member);
        } else if (oldMember != null) {
            member = guild.addMember(user, data.roles, oldMember.isDeafened(), oldMember.isMuted(), data.nick, false);
            guild.setPresence(data);
            loader.emit(new GuildMemberUpdateEvent(member, oldMember));
        } else {
            guild.setPresence(data);
        }
    }
}
Also used : UserUpdateEvent(io.discloader.discloader.common.event.UserUpdateEvent) User(io.discloader.discloader.core.entity.user.User) IUser(io.discloader.discloader.entity.user.IUser) GuildMemberUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent) IUser(io.discloader.discloader.entity.user.IUser) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PresenceJSON(io.discloader.discloader.network.json.PresenceJSON) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 8 with IUser

use of io.discloader.discloader.entity.user.IUser 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)

Example 9 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class TypingStart method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    TypingStartJSON data = gson.fromJson(d, TypingStartJSON.class);
    ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
    if (channel == null)
        return;
    IUser user = EntityRegistry.getUserByID(data.user_id);
    if (user == null || channel.getTyping() == null)
        return;
    channel.getTyping().put(user.getID(), user);
    TypingStartEvent e = new TypingStartEvent(user, channel);
    loader.emit(e);
    loader.emit("TypingStart", e);
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) TypingStartJSON(io.discloader.discloader.network.json.TypingStartJSON) IUser(io.discloader.discloader.entity.user.IUser) TypingStartEvent(io.discloader.discloader.common.event.channel.TypingStartEvent)

Example 10 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class EntityRegistry method addUser.

public static IUser addUser(UserJSON data) {
    if (data == null)
        return null;
    if (userExists(data.id == null ? "0" : data.id))
        return getUserByID(data.id == null ? "0" : data.id);
    IUser user = EntityBuilder.getUserFactory().buildUser(data);
    users.put(user.getID(), user);
    return user;
}
Also used : IUser(io.discloader.discloader.entity.user.IUser)

Aggregations

IUser (io.discloader.discloader.entity.user.IUser)10 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)3 IGuild (io.discloader.discloader.entity.guild.IGuild)3 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IMessage (io.discloader.discloader.entity.message.IMessage)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 GuildMemberRemoveJSON (io.discloader.discloader.network.json.GuildMemberRemoveJSON)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 UserUpdateEvent (io.discloader.discloader.common.event.UserUpdateEvent)1 TypingStartEvent (io.discloader.discloader.common.event.channel.TypingStartEvent)1 GuildBanAddEvent (io.discloader.discloader.common.event.guild.GuildBanAddEvent)1 GuildBanRemoveEvent (io.discloader.discloader.common.event.guild.GuildBanRemoveEvent)1 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)1 MessageReactionAddEvent (io.discloader.discloader.common.event.message.MessageReactionAddEvent)1 MessageReactionRemoveEvent (io.discloader.discloader.common.event.message.MessageReactionRemoveEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 User (io.discloader.discloader.core.entity.user.User)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1