Java Code Examples for net.dv8tion.jda.api.entities.Guild#getMemberById()

The following examples show how to use net.dv8tion.jda.api.entities.Guild#getMemberById() . 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: SupportRolesFeatureSetProvider.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Set<FeatureSet> getByUser(long userId) {
    Long guildId = workerProperties.getSupport().getGuildId();
    if (!discordService.isConnected(guildId)) {
        return Collections.emptySet();
    }
    Guild guild = discordService.getGuildById(guildId);
    if (guild == null) {
        return Collections.emptySet();
    }
    Member member = guild.getMemberById(userId);
    if (member == null) {
        return Collections.emptySet();
    }
    return member.getRoles().stream()
            .map(r -> workerProperties.getSupport().getFeaturedRoles().get(r.getId()))
            .filter(Objects::nonNull)
            .flatMap(Collection::stream)
            .collect(Collectors.toSet());
}
 
Example 3
Source File: UPunishment.java    From Arraybot with Apache License 2.0 6 votes vote down vote up
/**
 * Applies or removes the muted role to the specified user.
 * This method is used to permanently mute.
 * @param guild The guild.
 * @param punishedId The ID of the muted user.
 * @param apply True: adds role, false: removes role.
 * @return A pair of success and whether the punishment needs to be revoked.
 */
private static Pair<Boolean, Boolean> manageMute(Guild guild, long punishedId, boolean apply) {
    GuildEntry entry = (GuildEntry) Category.GUILD.getEntry();
    String mutedRoleId = entry.fetch(entry.getField(GuildEntry.Fields.MUTE_ROLE), guild.getIdLong(), null);
    Member muted = guild.getMemberById(punishedId);
    Role mutedRole = guild.getRoleById(mutedRoleId);
    if(muted == null
            || mutedRole == null) {
        return new Pair<>(false, false);
    }
    try {
        if(apply) {
            guild.addRoleToMember(muted, mutedRole).queue();
        } else {
            guild.removeRoleFromMember(muted, mutedRole).queue();
        }
        return new Pair<>(true, false);
    } catch(PermissionException exception) {
        return new Pair<>(false, false);
    }
}
 
Example 4
Source File: UUser.java    From Arraybot with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the member corresponding to the given user input.
 * @param guild The guild.
 * @param input The input.
 * @return A Member object, or null if the input is invalid.
 */
public static Member getMember(Guild guild, String input) {
    if(ID_PATTERN.matcher(input).find()
            || MENTION_PATTERN.matcher(input).find()) {
        return guild.getMemberById(input.replaceAll("\\D", ""));
    } else if(NAME_PATTERN.matcher(input).find()) {
        String name = input.substring(0, input.indexOf("#"));
        String discriminator = input.substring(input.indexOf("#") + 1);
        return guild.getMembers().stream()
                .filter(user -> user.getUser().getName().equals(name)
                    && user.getUser().getDiscriminator().equals(discriminator))
                .findFirst()
                .orElse(null);
    } else {
        return null;
    }
}
 
Example 5
Source File: LuckPermsHook.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void calculate(@NonNull Player target, @NonNull ContextConsumer consumer) {
    String userId = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(target.getUniqueId());
    consumer.accept(CONTEXT_LINKED, Boolean.toString(userId != null));

    if (userId == null) {
        return;
    }

    Guild mainGuild = DiscordSRV.getPlugin().getMainGuild();
    if (mainGuild == null) {
        return;
    }

    Member member = mainGuild.getMemberById(userId);
    if (member == null) {
        return;
    }

    consumer.accept(CONTEXT_BOOSTING, Boolean.toString(member.getTimeBoosted() != null));

    for (Role role : member.getRoles()) {
        consumer.accept(CONTEXT_ROLE, role.getName());
    }
}
 
Example 6
Source File: RankingQueueListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@RabbitListener(queues = RabbitConfiguration.QUEUE_RANKING_UPDATE_REQUEST)
public void updateRanking(RankingUpdateRequest request) {
    Guild guild = getGuildById(request.getGuildId());
    if (guild == null) {
        return;
    }

    Member member = guild.getMemberById(request.getUserId());
    if (member != null) {
        rankingService.updateRewards(member);
    }
}
 
Example 7
Source File: HistoryServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Transactional
public void onMessageDelete(TextChannel channel, String messageId) {
    Guild guild = channel.getGuild();
    if (isDisabled(guild)) {
        return;
    }
    MessageHistory history = historyRepository.findByMessageId(messageId);
    if (history == null) {
        return;
    }
    historyRepository.delete(history);

    AuditActionBuilder builder = auditService.log(guild, AuditActionType.MESSAGE_DELETE)
            .withChannel(channel)
            .withAttribute(MESSAGE_ID, messageId)
            .withAttribute(OLD_CONTENT, decrypt(channel, history));

    Member member = guild.getMemberById(history.getUserId());
    if (member != null) {
        builder.withUser(member);
    } else {
        LocalMember localMember = memberService.get(guild.getIdLong(), history.getUserId());
        if (localMember != null) {
            builder.withUser(localMember);
        }
    }
    builder.save();
}
 
Example 8
Source File: UnMuteJob.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(JobExecutionContext jobExecutionContext) {
    ShardManager shardManager = discordService.getShardManager();
    if (shardManager == null || !discordService.isConnected()) {
        reschedule(jobExecutionContext, TimeUnit.MINUTES, 1);
        return;
    }

    JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();

    String userId = data.getString(ATTR_USER_ID);
    String guildId = data.getString(ATTR_GUILD_ID);
    String channelId = data.getString(ATTR_CHANNEL_ID);

    if (guildId != null && userId != null && channelId != null) {
        muteService.clearState(Long.parseLong(guildId), userId, channelId);
    }

    if (StringUtils.isEmpty(guildId)) {
        return;
    }

    Guild guild = shardManager.getGuildById(guildId);
    if (guild != null) {
        if (!guild.isAvailable()) {
            reschedule(jobExecutionContext, TimeUnit.MINUTES, 1);
            return;
        }
        Member member = guild.getMemberById(userId);
        if (member != null) {
            TextChannel channel = StringUtils.isNotBlank(channelId) ? guild.getTextChannelById(channelId) : null;
            muteService.unmute(null, channel, member);
        }
    }
}
 
Example 9
Source File: TrackRequest.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public Member getMember() {
    Guild guild = jda.getGuildById(guildId);
    return guild != null ? guild.getMemberById(memberId) : null;
}
 
Example 10
Source File: MafiaPlayer.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public Member getMember() {
    Guild guild = jda.getGuildById(guildId);
    return guild != null ? guild.getMemberById(memberId) : null;
}