Search in sources :

Example 1 with UserUpdateEvent

use of sx.blah.discord.handle.impl.events.user.UserUpdateEvent in project Discord4J by Discord4J.

the class DispatchHandler method presenceUpdate.

private void presenceUpdate(PresenceUpdateEventResponse event) {
    IPresence presence = DiscordUtils.getPresenceFromJSON(event);
    Guild guild = event.guild_id == null ? null : (Guild) client.getGuildByID(Long.parseUnsignedLong(event.guild_id));
    if (guild != null) {
        User user = (User) guild.getUserByID(Long.parseUnsignedLong(event.user.id));
        if (user != null) {
            if (event.user.username != null) {
                // Full object was sent so there is a user change, otherwise all user fields but id would be null
                IUser oldUser = user.copy();
                user = DiscordUtils.getUserFromJSON(shard, event.user);
                client.dispatcher.dispatch(new UserUpdateEvent(oldUser, user));
            }
            if (!user.getPresence().equals(presence)) {
                IPresence oldPresence = user.getPresence();
                user.setPresence(presence);
                client.dispatcher.dispatch(new PresenceUpdateEvent(user, oldPresence, presence));
                Discord4J.LOGGER.debug(LogMarkers.PRESENCES, "User \"{}\" changed presence to {}", user.getName(), user.getPresence());
            }
        }
    }
}
Also used : UserUpdateEvent(sx.blah.discord.handle.impl.events.user.UserUpdateEvent) PresenceUpdateEvent(sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent)

Example 2 with UserUpdateEvent

use of sx.blah.discord.handle.impl.events.user.UserUpdateEvent in project Discord4J by Discord4J.

the class DispatchHandler method userUpdate.

private void userUpdate(UserUpdateEventResponse event) {
    User newUser = (User) client.getUserByID(Long.parseUnsignedLong(event.id));
    if (newUser != null) {
        IUser oldUser = newUser.copy();
        newUser = DiscordUtils.getUserFromJSON(shard, event);
        client.dispatcher.dispatch(new UserUpdateEvent(oldUser, newUser));
    }
}
Also used : UserUpdateEvent(sx.blah.discord.handle.impl.events.user.UserUpdateEvent)

Aggregations

UserUpdateEvent (sx.blah.discord.handle.impl.events.user.UserUpdateEvent)2 PresenceUpdateEvent (sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent)1