net.dv8tion.jda.api.exceptions.InsufficientPermissionException Java Examples
The following examples show how to use
net.dv8tion.jda.api.exceptions.InsufficientPermissionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChannelManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override @CheckReturnValue public ChannelManagerImpl removePermissionOverride(@Nonnull IPermissionHolder permHolder) { Checks.notNull(permHolder, "PermissionHolder"); Checks.check(permHolder.getGuild().equals(getGuild()), "PermissionHolder is not from the same Guild!"); if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(getChannel(), Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder); withLock(lock, (lock) -> { this.overridesRem.add(id); this.overridesAdd.remove(id); set |= PERMISSION; }); return this; }
Example #2
Source File: TextChannelImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<CompletableFuture<Void>> purgeMessages(@Nonnull List<? extends Message> messages) { if (messages == null || messages.isEmpty()) return Collections.emptyList(); boolean hasPerms = getGuild().getSelfMember().hasPermission(this, Permission.MESSAGE_MANAGE); if (!hasPerms) { for (Message m : messages) { if (m.getAuthor().equals(getJDA().getSelfUser())) continue; throw new InsufficientPermissionException(this, Permission.MESSAGE_MANAGE, "Cannot delete messages of other users"); } } return TextChannel.super.purgeMessages(messages); }
Example #3
Source File: PermissionOverrideImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public PermissionOverrideAction getManager() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(getChannel(), Permission.MANAGE_PERMISSIONS); PermissionOverrideAction mng = manager; if (mng == null) { mng = MiscUtil.locked(mngLock, () -> { if (manager == null) manager = new PermissionOverrideActionImpl(this).setOverride(false); return manager; }); } return mng.reset(); }
Example #4
Source File: GuildImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public RestActionImpl<List<Ban>> retrieveBanList() { if (!getSelfMember().hasPermission(Permission.BAN_MEMBERS)) throw new InsufficientPermissionException(this, Permission.BAN_MEMBERS); Route.CompiledRoute route = Route.Guilds.GET_BANS.compile(getId()); return new RestActionImpl<>(getJDA(), route, (response, request) -> { EntityBuilder builder = api.getEntityBuilder(); List<Ban> bans = new LinkedList<>(); DataArray bannedArr = response.getArray(); for (int i = 0; i < bannedArr.length(); i++) { final DataObject object = bannedArr.getObject(i); DataObject user = object.getObject("user"); bans.add(new Ban(builder.createFakeUser(user), object.getString("reason", null))); } return Collections.unmodifiableList(bans); }); }
Example #5
Source File: AbstractChannelImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public RestAction<List<Invite>> retrieveInvites() { if (!this.getGuild().getSelfMember().hasPermission(this, Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(this, Permission.MANAGE_CHANNEL); final Route.CompiledRoute route = Route.Invites.GET_CHANNEL_INVITES.compile(getId()); JDAImpl jda = (JDAImpl) getJDA(); return new RestActionImpl<>(jda, route, (response, request) -> { EntityBuilder entityBuilder = jda.getEntityBuilder(); DataArray array = response.getArray(); List<Invite> invites = new ArrayList<>(array.length()); for (int i = 0; i < array.length(); i++) invites.add(entityBuilder.createInvite(array.getObject(i))); return Collections.unmodifiableList(invites); }); }
Example #6
Source File: GuildImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public RestAction<Ban> retrieveBanById(@Nonnull String userId) { if (!getSelfMember().hasPermission(Permission.BAN_MEMBERS)) throw new InsufficientPermissionException(this, Permission.BAN_MEMBERS); Checks.isSnowflake(userId, "User ID"); Route.CompiledRoute route = Route.Guilds.GET_BAN.compile(getId(), userId); return new RestActionImpl<>(getJDA(), route, (response, request) -> { EntityBuilder builder = api.getEntityBuilder(); DataObject bannedObj = response.getObject(); DataObject user = bannedObj.getObject("user"); return new Ban(builder.createFakeUser(user), bannedObj.getString("reason", null)); }); }
Example #7
Source File: GuildImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override public RestAction<List<Invite>> retrieveInvites() { if (!this.getSelfMember().hasPermission(Permission.MANAGE_SERVER)) throw new InsufficientPermissionException(this, Permission.MANAGE_SERVER); final Route.CompiledRoute route = Route.Invites.GET_GUILD_INVITES.compile(getId()); return new RestActionImpl<>(getJDA(), route, (response, request) -> { EntityBuilder entityBuilder = api.getEntityBuilder(); DataArray array = response.getArray(); List<Invite> invites = new ArrayList<>(array.length()); for (int i = 0; i < array.length(); i++) invites.add(entityBuilder.createInvite(array.getObject(i))); return Collections.unmodifiableList(invites); }); }
Example #8
Source File: ChannelManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override @CheckReturnValue public ChannelManagerImpl putPermissionOverride(@Nonnull IPermissionHolder permHolder, long allow, long deny) { Checks.notNull(permHolder, "PermissionHolder"); Checks.check(permHolder.getGuild().equals(getGuild()), "PermissionHolder is not from the same Guild!"); if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(getChannel(), Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder); final int type = permHolder instanceof Role ? PermOverrideData.ROLE_TYPE : PermOverrideData.MEMBER_TYPE; withLock(lock, (lock) -> { this.overridesRem.remove(id); this.overridesAdd.put(id, new PermOverrideData(type, id, allow, deny)); set |= PERMISSION; }); return this; }
Example #9
Source File: RoleManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
@Nonnull @Override @CheckReturnValue public RoleManagerImpl setPermissions(long perms) { long selfPermissions = PermissionUtil.getEffectivePermission(getGuild().getSelfMember()); setupPermissions(); long missingPerms = perms; // include permissions we want to set to missingPerms &= ~selfPermissions; // exclude permissions we have missingPerms &= ~this.permissions; // exclude permissions the role has // if any permissions remain, we have an issue if (missingPerms != 0 && isPermissionChecksEnabled()) { EnumSet<Permission> permissionList = Permission.getPermissions(missingPerms); if (!permissionList.isEmpty()) throw new InsufficientPermissionException(getGuild(), permissionList.iterator().next()); } this.permissions = perms; set |= PERMISSION; return this; }
Example #10
Source File: PlayerServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public VoiceChannel connectToChannel(PlaybackInstance instance, Member member) throws DiscordException { VoiceChannel channel = getDesiredChannel(member); if (channel == null) { return null; } if (!channel.getGuild().getSelfMember().hasPermission(channel, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK)) { throw new DiscordException("discord.global.voice.noAccess"); } try { lavaAudioService.openConnection(instance.getPlayer(), channel); } catch (InsufficientPermissionException e) { throw new DiscordException("discord.global.voice.noAccess", e); } return channel; }
Example #11
Source File: MessageBuilder.java From JDA with Apache License 2.0 | 6 votes |
/** * Creates a {@link MessageAction MessageAction} * with the current settings without building a {@link net.dv8tion.jda.api.entities.Message Message} instance first. * * @param channel * The not-null target {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel} * * @throws java.lang.IllegalArgumentException * If the provided channel is {@code null} * @throws net.dv8tion.jda.api.exceptions.PermissionException * If the currently logged in account does not have permission to send or read messages in this channel. * @throws java.lang.UnsupportedOperationException * If this is a PrivateChannel and both users (sender and receiver) are bots * * @return {@link MessageAction MessageAction} */ @Nonnull @CheckReturnValue public MessageAction sendTo(@Nonnull MessageChannel channel) { Checks.notNull(channel, "Target Channel"); switch (channel.getType()) { case TEXT: final TextChannel text = (TextChannel) channel; final Member self = text.getGuild().getSelfMember(); if (!self.hasPermission(text, Permission.MESSAGE_READ)) throw new InsufficientPermissionException(text, Permission.MESSAGE_READ); if (!self.hasPermission(text, Permission.MESSAGE_WRITE)) throw new InsufficientPermissionException(text, Permission.MESSAGE_WRITE); break; case PRIVATE: final PrivateChannel priv = (PrivateChannel) channel; if (priv.getUser().isBot() && channel.getJDA().getAccountType() == AccountType.BOT) throw new UnsupportedOperationException("Cannot send a private message between bots."); } final Route.CompiledRoute route = Route.Messages.SEND_MESSAGE.compile(channel.getId()); final MessageActionImpl action = new MessageActionImpl(channel.getJDA(), route, channel, builder); return action.tts(isTTS).embed(embed).nonce(nonce); }
Example #12
Source File: AudioManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
private void checkChannel(VoiceChannel channel, Member self) { EnumSet<Permission> perms = Permission.getPermissions(PermissionUtil.getEffectivePermission(channel, self)); if (!perms.contains(Permission.VOICE_CONNECT)) throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT); final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set! if (userLimit > 0 && !perms.contains(Permission.ADMINISTRATOR)) { // Check if we can actually join this channel // - If there is a userlimit // - If that userlimit is reached // - If we don't have voice move others permissions // VOICE_MOVE_OTHERS allows access because you would be able to move people out to // open up a slot anyway if (userLimit <= channel.getMembers().size() && !perms.contains(Permission.VOICE_MOVE_OTHERS)) { throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass"); } } }
Example #13
Source File: ChannelOrderActionImpl.java From JDA with Apache License 2.0 | 6 votes |
@Override protected RequestBody finalizeData() { final Member self = guild.getSelfMember(); if (!self.hasPermission(Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(guild, Permission.MANAGE_CHANNEL); DataArray array = DataArray.empty(); for (int i = 0; i < orderList.size(); i++) { GuildChannel chan = orderList.get(i); array.add(DataObject.empty() .put("id", chan.getId()) .put("position", i)); } return getRequestBody(array); }
Example #14
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public RestAction<Integer> retrievePrunableMemberCount(int days) { if (!getSelfMember().hasPermission(Permission.KICK_MEMBERS)) throw new InsufficientPermissionException(this, Permission.KICK_MEMBERS); Checks.check(days >= 1 && days <= 30, "Provided %d days must be between 1 and 30.", days); Route.CompiledRoute route = Route.Guilds.PRUNABLE_COUNT.compile(getId()).withQueryParams("days", Integer.toString(days)); return new RestActionImpl<>(getJDA(), route, (response, request) -> response.getObject().getInt("pruned")); }
Example #15
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public MemberAction addMember(@Nonnull String accessToken, @Nonnull String userId) { Checks.notBlank(accessToken, "Access-Token"); Checks.isSnowflake(userId, "User ID"); Checks.check(getMemberById(userId) == null, "User is already in this guild"); if (!getSelfMember().hasPermission(Permission.CREATE_INSTANT_INVITE)) throw new InsufficientPermissionException(this, Permission.CREATE_INSTANT_INVITE); return new MemberActionImpl(getJDA(), this, userId, accessToken); }
Example #16
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override @Deprecated public RestAction<String> retrieveVanityUrl() { if (!getSelfMember().hasPermission(Permission.MANAGE_SERVER)) throw new InsufficientPermissionException(this, Permission.MANAGE_SERVER); if (!getFeatures().contains("VANITY_URL")) throw new IllegalStateException("This guild doesn't have a vanity url"); Route.CompiledRoute route = Route.Guilds.GET_VANITY_URL.compile(getId()); return new RestActionImpl<>(getJDA(), route, (response, request) -> response.getObject().getString("code")); }
Example #17
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public RestAction<List<Webhook>> retrieveWebhooks() { if (!getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) throw new InsufficientPermissionException(this, Permission.MANAGE_WEBHOOKS); Route.CompiledRoute route = Route.Guilds.GET_WEBHOOKS.compile(getId()); return new RestActionImpl<>(getJDA(), route, (response, request) -> { DataArray array = response.getArray(); List<Webhook> webhooks = new ArrayList<>(array.length()); EntityBuilder builder = api.getEntityBuilder(); for (int i = 0; i < array.length(); i++) { try { webhooks.add(builder.createWebhook(array.getObject(i))); } catch (UncheckedIOException | NullPointerException e) { JDAImpl.LOG.error("Error creating webhook from json", e); } } return Collections.unmodifiableList(webhooks); }); }
Example #18
Source File: JdaLink.java From Lavalink-Client with MIT License | 5 votes |
/** * Eventually connect to a channel. Takes care of disconnecting from an existing connection * * @param channel Channel to connect to */ @SuppressWarnings("WeakerAccess") void connect(VoiceChannel channel, boolean checkChannel) { if (!channel.getGuild().equals(getJda().getGuildById(guild))) throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." + "Please provide a VoiceChannel from the proper Guild"); if (channel.getJDA().isUnavailable(channel.getGuild().getIdLong())) throw new GuildUnavailableException("Cannot open an Audio Connection with an unavailable guild. " + "Please wait until this Guild is available to open a connection."); final Member self = channel.getGuild().getSelfMember(); if (!self.hasPermission(channel, Permission.VOICE_CONNECT) && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT); //If we are already connected to this VoiceChannel, then do nothing. if (checkChannel && channel.equals(channel.getGuild().getSelfMember().getVoiceState().getChannel())) return; if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set! if (!self.isOwner() && !self.hasPermission(Permission.ADMINISTRATOR)) { if (userLimit > 0 // If there is a userlimit && userLimit <= channel.getMembers().size() // if that userlimit is reached && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) // If we don't have voice move others permissions throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, // then throw exception! "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass"); } } setState(State.CONNECTING); queueAudioConnect(channel.getIdLong()); }
Example #19
Source File: MessagePaginationActionImpl.java From JDA with Apache License 2.0 | 5 votes |
public MessagePaginationActionImpl(MessageChannel channel) { super(channel.getJDA(), Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()), 1, 100, 100); if (channel.getType() == ChannelType.TEXT) { TextChannel textChannel = (TextChannel) channel; if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_HISTORY)) throw new InsufficientPermissionException(textChannel, Permission.MESSAGE_HISTORY); } this.channel = channel; }
Example #20
Source File: AuditLogPaginationActionImpl.java From JDA with Apache License 2.0 | 5 votes |
public AuditLogPaginationActionImpl(Guild guild) { super(guild.getJDA(), Route.Guilds.GET_AUDIT_LOGS.compile(guild.getId()), 1, 100, 100); if (!guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) throw new InsufficientPermissionException(guild, Permission.VIEW_AUDIT_LOGS); this.guild = guild; }
Example #21
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable VoiceChannel voiceChannel) { Checks.notNull(member, "Member"); checkGuild(member.getGuild(), "Member"); if (voiceChannel != null) checkGuild(voiceChannel.getGuild(), "VoiceChannel"); GuildVoiceState vState = member.getVoiceState(); if (vState == null) throw new IllegalStateException("Cannot move a Member with disabled CacheFlag.VOICE_STATE"); VoiceChannel channel = vState.getChannel(); if (channel == null) throw new IllegalStateException("You cannot move a Member who isn't in a VoiceChannel!"); if (!PermissionUtil.checkPermission(channel, getSelfMember(), Permission.VOICE_MOVE_OTHERS)) throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, "This account does not have Permission to MOVE_OTHERS out of the channel that the Member is currently in."); if (voiceChannel != null && !PermissionUtil.checkPermission(voiceChannel, getSelfMember(), Permission.VOICE_CONNECT) && !PermissionUtil.checkPermission(voiceChannel, member, Permission.VOICE_CONNECT)) throw new InsufficientPermissionException(voiceChannel, Permission.VOICE_CONNECT, "Neither this account nor the Member that is attempting to be moved have the VOICE_CONNECT permission " + "for the destination VoiceChannel, so the move cannot be done."); DataObject body = DataObject.empty().put("channel_id", voiceChannel == null ? null : voiceChannel.getId()); Route.CompiledRoute route = Route.Guilds.MODIFY_MEMBER.compile(getId(), member.getUser().getId()); return new RestActionImpl<>(getJDA(), route, body); }
Example #22
Source File: GuildImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public AuditableRestAction<Void> modifyNickname(@Nonnull Member member, String nickname) { Checks.notNull(member, "Member"); checkGuild(member.getGuild(), "Member"); if (member.equals(getSelfMember())) { if (!member.hasPermission(Permission.NICKNAME_CHANGE) && !member.hasPermission(Permission.NICKNAME_MANAGE)) throw new InsufficientPermissionException(this, Permission.NICKNAME_CHANGE, "You neither have NICKNAME_CHANGE nor NICKNAME_MANAGE permission!"); } else { checkPermission(Permission.NICKNAME_MANAGE); checkPosition(member); } JDAImpl jda = getJDA(); return new DeferredRestAction<>(jda, () -> { DataObject body = DataObject.empty().put("nick", nickname == null ? "" : nickname); Route.CompiledRoute route; if (member.equals(getSelfMember())) route = Route.Guilds.MODIFY_SELF_NICK.compile(getId()); else route = Route.Guilds.MODIFY_MEMBER.compile(getId(), member.getUser().getId()); return new AuditableRestActionImpl<Void>(jda, route, body); }).setCacheCheck(() -> !Objects.equals(nickname, member.getNickname())); }
Example #23
Source File: RoleImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public AuditableRestAction<Void> delete() { Guild guild = getGuild(); if (!guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES)) throw new InsufficientPermissionException(guild, Permission.MANAGE_ROLES); if(!PermissionUtil.canInteract(guild.getSelfMember(), this)) throw new HierarchyException("Can't delete role >= highest self-role"); if (managed) throw new UnsupportedOperationException("Cannot delete a Role that is managed. "); Route.CompiledRoute route = Route.Roles.DELETE_ROLE.compile(guild.getId(), getId()); return new AuditableRestActionImpl<>(getJDA(), route); }
Example #24
Source File: MessageActionImpl.java From JDA with Apache License 2.0 | 5 votes |
protected void checkPermission(Permission perm) { if (!hasPermission(perm)) { TextChannel channel = (TextChannel) this.channel; throw new InsufficientPermissionException(channel, perm); } }
Example #25
Source File: RoleOrderActionImpl.java From JDA with Apache License 2.0 | 5 votes |
@Override protected RequestBody finalizeData() { final Member self = guild.getSelfMember(); final boolean isOwner = self.isOwner(); if (!isOwner) { if (self.getRoles().isEmpty()) throw new IllegalStateException("Cannot move roles above your highest role unless you are the guild owner"); if (!self.hasPermission(Permission.MANAGE_ROLES)) throw new InsufficientPermissionException(guild, Permission.MANAGE_ROLES); } DataArray array = DataArray.empty(); List<Role> ordering = new ArrayList<>(orderList); //If not in normal discord order, reverse. // Normal order is descending, not ascending. if (ascendingOrder) Collections.reverse(ordering); for (int i = 0; i < ordering.size(); i++) { Role role = ordering.get(i); final int initialPos = role.getPosition(); if (initialPos != i && !isOwner && !self.canInteract(role)) // If the current role was moved, we are not owner and we can't interact with the role then throw a PermissionException throw new IllegalStateException("Cannot change order: One of the roles could not be moved due to hierarchical power!"); array.add(DataObject.empty() .put("id", role.getId()) .put("position", i + 1)); //plus 1 because position 0 is the @everyone position. } return getRequestBody(array); }
Example #26
Source File: EmoteImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public AuditableRestAction<Void> delete() { if (getGuild() == null) throw new IllegalStateException("The emote you are trying to delete is not an actual emote we have access to (it is fake)!"); if (managed) throw new UnsupportedOperationException("You cannot delete a managed emote!"); if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_EMOTES)) throw new InsufficientPermissionException(getGuild(), Permission.MANAGE_EMOTES); Route.CompiledRoute route = Route.Emotes.DELETE_EMOTE.compile(getGuild().getId(), getId()); return new AuditableRestActionImpl<>(getJDA(), route); }
Example #27
Source File: PermissionOverrideActionImpl.java From JDA with Apache License 2.0 | 5 votes |
@Override protected BooleanSupplier finalizeChecks() { return () -> { if (!getGuild().getSelfMember().hasPermission(channel, Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(channel, Permission.MANAGE_PERMISSIONS); return true; }; }
Example #28
Source File: ChannelManagerImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override @CheckReturnValue public ChannelManagerImpl sync(@Nonnull GuildChannel syncSource) { Checks.notNull(syncSource, "SyncSource"); Checks.check(getGuild().equals(syncSource.getGuild()), "Sync only works for channels of same guild"); if(syncSource.equals(getChannel())) return this; if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(getChannel(), Permission.MANAGE_PERMISSIONS); withLock(lock, (lock) -> { this.overridesRem.clear(); this.overridesAdd.clear(); //set all current overrides to-be-removed getChannel().getPermissionOverrides() .stream() .mapToLong(PermissionOverride::getIdLong) .forEach(overridesRem::add); //re-add all perm-overrides of syncSource syncSource.getPermissionOverrides().forEach(override -> { int type = override.isRoleOverride() ? PermOverrideData.ROLE_TYPE : PermOverrideData.MEMBER_TYPE; long id = override.getIdLong(); this.overridesRem.remove(id); this.overridesAdd.put(id, new PermOverrideData(type, id, override.getAllowedRaw(), override.getDeniedRaw())); }); set |= PERMISSION; }); return this; }
Example #29
Source File: MessageHistory.java From JDA with Apache License 2.0 | 5 votes |
/** * Creates a new MessageHistory object. * * @param channel * The {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel} to retrieval history from. */ public MessageHistory(@Nonnull MessageChannel channel) { Checks.notNull(channel, "Channel"); this.channel = channel; if (channel instanceof TextChannel) { TextChannel tc = (TextChannel) channel; if (!tc.getGuild().getSelfMember().hasPermission(tc, Permission.MESSAGE_HISTORY)) throw new InsufficientPermissionException(tc, Permission.MESSAGE_HISTORY); } }
Example #30
Source File: MessageHistory.java From JDA with Apache License 2.0 | 5 votes |
private static void checkArguments(MessageChannel channel, String messageId) { Checks.isSnowflake(messageId, "Message ID"); Checks.notNull(channel, "Channel"); if (channel.getType() == ChannelType.TEXT) { TextChannel t = (TextChannel) channel; if (!t.getGuild().getSelfMember().hasPermission(t, Permission.MESSAGE_HISTORY)) throw new InsufficientPermissionException(t, Permission.MESSAGE_HISTORY); } }