use of sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent in project Discord4J by Discord4J.
the class ShardImpl method updatePresence.
private void updatePresence(StatusType status, ActivityType type, String text, String streamUrl) {
checkLoggedIn("update presence");
if (streamUrl != null) {
if (!DiscordUtils.STREAM_URL_PATTERN.matcher(streamUrl).matches()) {
throw new IllegalArgumentException("Stream URL must be a twitch.tv url.");
}
}
IUser ourUser = getClient().getOurUser();
IPresence oldPresence = ourUser.getPresence();
IPresence newPresence = new Presence(text, streamUrl, status, type);
if (!newPresence.equals(oldPresence)) {
((User) ourUser).setPresence(newPresence);
getClient().getDispatcher().dispatch(new PresenceUpdateEvent(ourUser, oldPresence, newPresence));
}
ws.send(GatewayOps.STATUS_UPDATE, new PresenceUpdateRequest(status, type, text, streamUrl));
}
use of sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent 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());
}
}
}
}
Aggregations