private void checkPermission(Permission permission) { if (!guild.getSelfMember().hasPermission(permission)) throw new InsufficientPermissionException(permission); } }
@Override protected RequestBody finalizeData() { final Member self = guild.getSelfMember(); if (!self.hasPermission(Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(Permission.MANAGE_CHANNEL); JSONArray array = new JSONArray(); for (int i = 0; i < orderList.size(); i++) { Channel chan = orderList.get(i); array.put(new JSONObject() .put("id", chan.getId()) .put("position", i)); } return getRequestBody(array); }
protected void checkPosition(Role role) { if(!getGuild().getSelfMember().canInteract(role)) throw new HierarchyException("Can't modify a role with higher or equal highest role than yourself! Role: " + role.toString()); } }
protected void checkPermission(Permission perm) { if (!getGuild().getSelfMember().hasPermission(perm)) throw new InsufficientPermissionException(perm); }
protected boolean hasPermission(Permission perm) { if (channel.getType() != ChannelType.TEXT) return true; TextChannel text = (TextChannel) channel; Member self = text.getGuild().getSelfMember(); return self.hasPermission(text, perm); }
protected void checkPosition(Member member) { if(!getGuild().getSelfMember().canInteract(member)) throw new HierarchyException("Can't modify a member with higher or equal highest role than yourself!"); }
/** * Creates a new MessageHistory object. * * @param channel * The {@link net.dv8tion.jda.core.entities.MessageChannel MessageChannel} to retrieval history from. */ public MessageHistory(MessageChannel channel) { this.channel = channel; if (channel instanceof TextChannel) { TextChannel tc = (TextChannel) channel; if (!tc.getGuild().getSelfMember().hasPermission(tc, Permission.MESSAGE_HISTORY)) throw new InsufficientPermissionException(Permission.MESSAGE_HISTORY); } }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_SERVER)) throw new InsufficientPermissionException(Permission.MANAGE_SERVER); return super.checkPermissions(); } }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_EMOTES)) throw new InsufficientPermissionException(Permission.MANAGE_EMOTES); return super.checkPermissions(); } }
private void checkPermission(Permission permission) { if (channel.getType() == ChannelType.TEXT) { Channel location = (Channel) channel; if (!location.getGuild().getSelfMember().hasPermission(location, permission)) throw new InsufficientPermissionException(permission); } }
public AuditLogPaginationAction(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(Permission.VIEW_AUDIT_LOGS); this.guild = guild; }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_WEBHOOKS)) throw new InsufficientPermissionException(Permission.MANAGE_WEBHOOKS); return super.checkPermissions(); } }
@Override protected boolean checkPermissions() { final Member selfMember = getGuild().getSelfMember(); if (!selfMember.hasPermission(getChannel(), Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(Permission.MANAGE_CHANNEL); return super.checkPermissions(); }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); return super.checkPermissions(); } }
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(Permission.MESSAGE_HISTORY); } }
@Override public AuditableRestAction<Void> delete() { if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_ROLES)) throw new InsufficientPermissionException(Permission.MANAGE_ROLES); if(!PermissionUtil.canInteract(getGuild().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(getGuild().getId(), getId()); return new AuditableRestAction<Void>(getJDA(), route) { @Override protected void handleResponse(Response response, Request<Void> request) { if (response.isOk()) request.onSuccess(null); else request.onFailure(response); } }; }
@Override public AuditableRestAction<Void> delete() { if (!getJDA().getSelfUser().equals(getAuthor())) { if (isFromType(ChannelType.PRIVATE) || isFromType(ChannelType.GROUP)) throw new IllegalStateException("Cannot delete another User's messages in a Group or PrivateChannel."); else if (!getGuild().getSelfMember() .hasPermission((TextChannel) getChannel(), Permission.MESSAGE_MANAGE)) throw new InsufficientPermissionException(Permission.MESSAGE_MANAGE); } return channel.deleteMessageById(getIdLong()); }
public MessagePaginationAction(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(Permission.MESSAGE_HISTORY); } this.channel = channel; }
@Override protected boolean checkPermissions() { Member selfMember = getGuild().getSelfMember(); if (!selfMember.hasPermission(Permission.MANAGE_ROLES)) throw new InsufficientPermissionException(Permission.MANAGE_ROLES); if (!selfMember.canInteract(getRole())) throw new HierarchyException("Cannot modify a role that is higher or equal in hierarchy"); return super.checkPermissions(); /* //we can't reliably check the permissions of the role here long missingRaw = permissions; missingRaw &= ~selfPermissions; // exclude own perms missingRaw &= ~role.getPermissionsRaw(); // exclude role perms if (missingRaw != 0) { List<Permission> missingPermissions = Permission.getPermissions(missingRaw); if (!missingPermissions.isEmpty()) throw new InsufficientPermissionException(missingPermissions.get(0)); } */ }
@Override public AuditableRestAction<Void> delete() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); String targetId = isRoleOverride() ? getRole().getId() : getMember().getUser().getId(); Route.CompiledRoute route = Route.Channels.DELETE_PERM_OVERRIDE.compile(getChannel().getId(), targetId); return new AuditableRestAction<Void>(getJDA(), route) { @Override protected void handleResponse(Response response, Request<Void> request) { if (response.isOk()) request.onSuccess(null); else request.onFailure(response); } }; }