Java Code Examples for net.dv8tion.jda.api.entities.Member#isOwner()

The following examples show how to use net.dv8tion.jda.api.entities.Member#isOwner() . 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: CheckOwnerQueueListener.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@RabbitListener(queues = RabbitConfiguration.QUEUE_CHECK_OWNER_REQUEST)
public boolean isAdministrator(CheckOwnerRequest request) {
    Guild guild = null;
    switch (request.getType()) {
        case TEXT:
            TextChannel textChannel = discordService.getTextChannelById(request.getChannelId());
            if (textChannel != null) {
                guild = textChannel.getGuild();
            }
            break;
        case VOICE:
            VoiceChannel voiceChannel = discordService.getVoiceChannelById(request.getChannelId());
            if (voiceChannel != null) {
                guild = voiceChannel.getGuild();
            }
            break;
    }
    if (guild == null) {
        return true;
    }
    Member member = guild.getMemberById(request.getUserId());
    if (member == null) {
        return false;
    }
    return member.isOwner() || member.hasPermission(Permission.ADMINISTRATOR);
}
 
Example 2
Source File: JdaLink.java    From Lavalink-Client with MIT License 5 votes vote down vote up
/**
 * 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 3
Source File: PlayerServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Transactional
public boolean hasAccess(Member member) {
    MusicConfig config = musicConfigService.get(member.getGuild());
    return config == null
            || CollectionUtils.isEmpty(config.getRoles())
            || member.isOwner()
            || member.hasPermission(Permission.ADMINISTRATOR)
            || member.getRoles().stream().anyMatch(e -> config.getRoles().contains(e.getIdLong()));
}
 
Example 4
Source File: ModerationServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Transactional(readOnly = true)
public boolean isModerator(Member member) {
    if (member == null) {
        return false;
    }
    if (member.hasPermission(Permission.ADMINISTRATOR) || member.isOwner()) {
        return true;
    }
    ModerationConfig config = moderationConfigService.get(member.getGuild());
    return config != null && CollectionUtils.isNotEmpty(config.getRoles())
            && member.getRoles().stream().anyMatch(e -> config.getRoles().contains(e.getIdLong()));
}
 
Example 5
Source File: RoleOrderActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@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);
}