List of usage examples for java.lang Long parseUnsignedLong
public static long parseUnsignedLong(String s) throws NumberFormatException
From source file:com.joyent.manta.http.HttpRange.java
/** * Deserialize a response (Content-Range) range. * * @param contentRange the string representation of the range * @return a {@link BoundedRequest} range * @throws ProtocolException if the range could not be parsed *///from ww w . j a v a2 s. c o m static Response parseContentRange(final String contentRange) throws ProtocolException { notNull(contentRange, "Content Range must not be null"); if (!contentRange.matches(REGEX_CONTENT_RANGE)) { final String message = String.format("Invalid content-range format, expected: " + "[bytes <startInclusive>-<endInclusive>/<size>], got: %s", contentRange); throw new ProtocolException(message); } final String[] boundsAndSize = StringUtils.split(StringUtils.removeStart(contentRange, "bytes "), "-/"); if (boundsAndSize.length != PART_COUNT_CONTENT_RANGE) { throw new ProtocolException(String.format("Malformed Range value, got: %s", contentRange)); } return new Response(Long.parseUnsignedLong(boundsAndSize[0]), Long.parseUnsignedLong(boundsAndSize[1]), Long.parseUnsignedLong(boundsAndSize[2])); }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void typingStart(TypingEventResponse event) { User user;//from w w w . j ava 2 s . co m Channel channel = (Channel) client.getChannelByID(Long.parseUnsignedLong(event.channel_id)); if (channel != null) { if (channel.isPrivate()) { user = (User) ((IPrivateChannel) channel).getRecipient(); } else { user = (User) channel.getGuild().getUserByID(Long.parseUnsignedLong(event.user_id)); } if (user != null) { client.dispatcher.dispatch(new TypingEvent(user, channel)); } } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
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)); }/*from w w w.j a v a2 s. c o m*/ 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()); } } } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildDelete(GuildObject json) { long guildId = Long.parseUnsignedLong(json.id); Guild guild = (Guild) client.getGuildByID(guildId); // Clean up cache if (guild != null) { ((ShardImpl) guild.getShard()).guildCache.remove(guild); ((User) client.getOurUser()).voiceStates.remove(guild.getLongID()); DiscordVoiceWS vWS = shard.voiceWebSockets.get(guildId); if (vWS != null) { vWS.disconnect(VoiceDisconnectedEvent.Reason.LEFT_CHANNEL); shard.voiceWebSockets.remove(guildId); }/* www .j a va 2 s . c om*/ } if (json.unavailable) { //Guild can't be reached Discord4J.LOGGER.warn(LogMarkers.WEBSOCKET, "Guild with id {} is unavailable, is there an outage?", json.id); client.dispatcher.dispatch(new GuildUnavailableEvent(guildId)); } else { Discord4J.LOGGER.debug(LogMarkers.EVENTS, "You have been kicked from or left \"{}\"! :O", guild.getName()); client.dispatcher.dispatch(new GuildLeaveEvent(guild)); } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void userUpdate(UserUpdateEventResponse event) { User newUser = (User) client.getUserByID(Long.parseUnsignedLong(event.id)); if (newUser != null) { IUser oldUser = newUser.copy();/*from w w w.j a v a 2 s . c o m*/ newUser = DiscordUtils.getUserFromJSON(shard, event); client.dispatcher.dispatch(new UserUpdateEvent(oldUser, newUser)); } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildMembersChunk(GuildMemberChunkEventResponse event) { Guild guildToUpdate = (Guild) client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guildToUpdate == null) { Discord4J.LOGGER.warn(LogMarkers.WEBSOCKET, "Can't receive guild members chunk for guild id {}, the guild is null!", event.guild_id); return;//from w w w. j a v a2s. c om } for (MemberObject member : event.members) { IUser user = DiscordUtils.getUserFromGuildMemberResponse(guildToUpdate, member); guildToUpdate.users.put(user); } if (guildToUpdate.getUsers().size() >= guildToUpdate.getTotalMemberCount()) { client.getDispatcher().dispatch(new AllUsersReceivedEvent(guildToUpdate)); } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildUpdate(GuildObject json) { Guild toUpdate = (Guild) client.getGuildByID(Long.parseUnsignedLong(json.id)); if (toUpdate != null) { IGuild oldGuild = toUpdate.copy(); toUpdate = (Guild) DiscordUtils.getGuildFromJSON(shard, json); if (toUpdate.getOwnerLongID() != oldGuild.getOwnerLongID()) { client.dispatcher.dispatch(/*from w w w . ja v a2s .co m*/ new GuildTransferOwnershipEvent(oldGuild.getOwner(), toUpdate.getOwner(), toUpdate)); } else { client.dispatcher.dispatch(new GuildUpdateEvent(oldGuild, toUpdate)); } } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildRoleCreate(GuildRoleEventResponse event) { IGuild guild = client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guild != null) { IRole role = DiscordUtils.getRoleFromJSON(guild, event.role); client.dispatcher.dispatch(new RoleCreateEvent(role)); }// www . j a v a 2 s . c o m }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildRoleUpdate(GuildRoleEventResponse event) { IGuild guild = client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guild != null) { IRole toUpdate = guild.getRoleByID(Long.parseUnsignedLong(event.role.id)); if (toUpdate != null) { IRole oldRole = toUpdate.copy(); toUpdate = DiscordUtils.getRoleFromJSON(guild, event.role); client.dispatcher.dispatch(new RoleUpdateEvent(oldRole, toUpdate)); if (guild.getRolesForUser(client.getOurUser()).contains(toUpdate)) ((Guild) guild).loadWebhooks(); }//from w ww . j av a 2s.c o m } }