List of usage examples for java.lang Long parseUnsignedLong
public static long parseUnsignedLong(String s) throws NumberFormatException
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildRoleDelete(GuildRoleDeleteEventResponse event) { Guild guild = (Guild) client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guild != null) { IRole role = guild.getRoleByID(Long.parseUnsignedLong(event.role_id)); if (role != null) { guild.roles.remove(role);/* w w w.j a v a 2s.co m*/ client.dispatcher.dispatch(new RoleDeleteEvent(role)); } } }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void guildBanRemove(GuildBanEventResponse event) { IGuild guild = client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guild != null) { IUser user = DiscordUtils.getUserFromJSON(shard, event.user); client.dispatcher.dispatch(new UserPardonEvent(guild, user)); }/* w w w . j a v a2s .co m*/ }
From source file:sx.blah.discord.handle.impl.obj.Guild.java
public void loadWebhooks() { try {/*w w w .ja v a 2s . c o m*/ PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_WEBHOOKS); } catch (MissingPermissionsException ignored) { return; } RequestBuffer.request(() -> { try { List<IWebhook> oldList = getWebhooks().stream().map(IWebhook::copy) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); WebhookObject[] response = ((DiscordClientImpl) client).REQUESTS.GET .makeRequest(DiscordEndpoints.GUILDS + getStringID() + "/webhooks", WebhookObject[].class); if (response != null) { for (WebhookObject webhookObject : response) { Channel channel = (Channel) getChannelByID( Long.parseUnsignedLong(webhookObject.channel_id)); long webhookId = Long.parseUnsignedLong(webhookObject.id); if (getWebhookByID(webhookId) == null) { IWebhook newWebhook = DiscordUtils.getWebhookFromJSON(channel, webhookObject); client.getDispatcher().dispatch(new WebhookCreateEvent(newWebhook)); channel.webhooks.put(newWebhook); } else { IWebhook toUpdate = channel.getWebhookByID(webhookId); IWebhook oldWebhook = toUpdate.copy(); toUpdate = DiscordUtils.getWebhookFromJSON(channel, webhookObject); if (!oldWebhook.getDefaultName().equals(toUpdate.getDefaultName()) || !String.valueOf(oldWebhook.getDefaultAvatar()) .equals(String.valueOf(toUpdate.getDefaultAvatar()))) client.getDispatcher().dispatch(new WebhookUpdateEvent(oldWebhook, toUpdate)); oldList.remove(oldWebhook); } } } oldList.forEach(webhook -> { ((Channel) webhook.getChannel()).webhooks.remove(webhook); client.getDispatcher().dispatch(new WebhookDeleteEvent(webhook)); }); } catch (Exception e) { Discord4J.LOGGER.warn(LogMarkers.HANDLE, "Discord4J Internal Exception", e); } }); }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void voiceStateUpdate(VoiceStateObject json) { User user = (User) shard.getUserByID(Long.parseUnsignedLong(json.user_id)); if (user != null) { IVoiceState curVoiceState = user.voiceStates.get(json.guild_id); IVoiceChannel channel = json.channel_id != null ? shard.getVoiceChannelByID(Long.parseUnsignedLong(json.channel_id)) : null;/*from w w w . ja v a 2 s . co m*/ IVoiceChannel oldChannel = curVoiceState == null ? null : curVoiceState.getChannel(); user.voiceStates.put(DiscordUtils .getVoiceStateFromJson(shard.getGuildByID(Long.parseUnsignedLong(json.guild_id)), json)); if (oldChannel != channel) { if (channel == null) { client.getDispatcher().dispatch(new UserVoiceChannelLeaveEvent(oldChannel, user)); } else if (oldChannel == null) { ((Guild) channel.getGuild()).connectingVoiceChannelID = 0; client.getDispatcher().dispatch(new UserVoiceChannelJoinEvent(channel, user)); } else if (oldChannel.getGuild().equals(channel.getGuild())) { client.getDispatcher().dispatch(new UserVoiceChannelMoveEvent(user, oldChannel, channel)); } } } }
From source file:sx.blah.discord.handle.impl.obj.Channel.java
/** * Forcibly loads and caches all webhooks for the channel. *//*from w w w . j a v a 2 s . c o m*/ public void loadWebhooks() { try { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_WEBHOOKS); } catch (MissingPermissionsException ignored) { return; } RequestBuffer.request(() -> { try { List<IWebhook> oldList = getWebhooks().stream().map(IWebhook::copy) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); WebhookObject[] response = ((DiscordClientImpl) client).REQUESTS.GET.makeRequest( DiscordEndpoints.CHANNELS + getStringID() + "/webhooks", WebhookObject[].class); if (response != null) { for (WebhookObject webhookObject : response) { long webhookId = Long.parseUnsignedLong(webhookObject.id); if (getWebhookByID(webhookId) == null) { IWebhook newWebhook = DiscordUtils.getWebhookFromJSON(this, webhookObject); client.getDispatcher().dispatch(new WebhookCreateEvent(newWebhook)); webhooks.put(newWebhook); } else { IWebhook toUpdate = getWebhookByID(webhookId); IWebhook oldWebhook = toUpdate.copy(); toUpdate = DiscordUtils.getWebhookFromJSON(this, webhookObject); if (!oldWebhook.getDefaultName().equals(toUpdate.getDefaultName()) || !String.valueOf(oldWebhook.getDefaultAvatar()) .equals(String.valueOf(toUpdate.getDefaultAvatar()))) client.getDispatcher().dispatch(new WebhookUpdateEvent(oldWebhook, toUpdate)); oldList.remove(oldWebhook); } } } oldList.forEach(webhook -> { webhooks.remove(webhook); client.getDispatcher().dispatch(new WebhookDeleteEvent(webhook)); }); } catch (Exception e) { Discord4J.LOGGER.warn(LogMarkers.HANDLE, "Discord4J Internal Exception", e); } }); }
From source file:com.joyent.manta.http.MantaHttpHeaders.java
/** * Translates the range request header into two values. The first value * is the starting bytes of the binary file to read and the second value * is the ending bytes of the file to read. If the range indicates the * end of a file (unlimited), then the end value will be set to null. * Likewise, if the start position is unknown, it will be set to null. * * This method may eventually be deprecated in favor of {@link HttpRange#parseRequestRange(String)} but * that refactoring is being deferred./*from www . j a v a 2s. co m*/ * * @return two value array containing the start and the end of a byte range as Long * * @see HttpRange#parseRequestRange(String) */ public Long[] getByteRange() { final String rangeString = getRange(); Validate.notNull(rangeString, "Range value must not be null"); String[] rangeValuesStrings = StringUtils.split(rangeString, "bytes="); Validate.isTrue(rangeValuesStrings.length == 1, "Range header value doesn't begin with string: bytes="); final String byteRange = rangeValuesStrings[0]; Validate.isTrue(StringUtils.split(byteRange, ",").length == 1, "Multi-range requests are not supported"); String[] rangeParts = StringUtils.split(byteRange, "-"); Validate.isTrue(StringUtils.countMatches(byteRange, "-") < 2, "Cannot end or start with a negative number"); Long startPos = null; Long endPos = null; if (StringUtils.startsWith(byteRange, "-")) { endPos = Long.parseLong(byteRange); } else if (StringUtils.endsWith(byteRange, "-")) { startPos = Long.parseLong(byteRange.split("-")[0]); } else if (rangeParts.length == 2) { startPos = Long.parseUnsignedLong(rangeParts[0]); endPos = Long.parseUnsignedLong(rangeParts[1]); } else { throw new IllegalArgumentException("range must exist with - separator"); } return new Long[] { startPos, endPos }; }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void webhookUpdate(WebhookObject event) { Channel channel = (Channel) client.getChannelByID(Long.parseUnsignedLong(event.channel_id)); if (channel != null) channel.loadWebhooks(); }
From source file:sx.blah.discord.api.internal.DiscordUtils.java
/** * Converts a json {@link UserObject} to a {@link User}. This method first checks the internal user cache and returns * that object with updated information if it exists. Otherwise, it constructs a new user. * * @param shard The shard the user belongs to. * @param response The json object representing the user. * @return The converted user object.//from w w w .j av a2s. c o m */ public static User getUserFromJSON(IShard shard, UserObject response) { if (response == null) return null; User user; if (shard != null && (user = (User) shard.getUserByID(Long.parseUnsignedLong(response.id))) != null) { user.setAvatar(response.avatar); user.setName(response.username); user.setDiscriminator(response.discriminator); } else { user = new User(shard, response.username, Long.parseUnsignedLong(response.id), response.discriminator, response.avatar, new Presence(null, null, StatusType.OFFLINE, ActivityType.PLAYING), response.bot); } return user; }
From source file:sx.blah.discord.api.internal.DiscordUtils.java
/** * Gets the users mentioned in a message. * * @param json The json response to use. * @return The list of IDs of mentioned users. *//*from ww w . j a v a2 s. c om*/ public static List<Long> getMentionsFromJSON(MessageObject json) { List<Long> mentions = new ArrayList<>(); if (json.mentions != null) for (UserObject response : json.mentions) mentions.add(Long.parseUnsignedLong(response.id)); return mentions; }
From source file:sx.blah.discord.api.internal.DiscordUtils.java
/** * Gets the roles mentioned in a message. * * @param json The json response to use. * @return The list IDs of mentioned roles. *//* www . ja va 2 s . c om*/ public static List<Long> getRoleMentionsFromJSON(MessageObject json) { List<Long> mentions = new ArrayList<>(); if (json.mention_roles != null) for (String role : json.mention_roles) mentions.add(Long.parseUnsignedLong(role)); return mentions; }