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());
}
}
}
}
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));
}
}
Aggregations