net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent. 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: GuildMemberAddHandler.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long id = content.getLong("guild_id");
    boolean setup = getJDA().getGuildSetupController().onAddMember(id, content);
    if (setup)
        return null;

    GuildImpl guild = (GuildImpl) getJDA().getGuildById(id);
    if (guild == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Caching member for guild that is not yet cached. Guild ID: {} JSON: {}", id, content);
        return null;
    }

    // Update memberCount
    guild.onMemberAdd();
    MemberImpl member = getJDA().getEntityBuilder().createMember(guild, content);
    getJDA().getEntityBuilder().updateMemberCache(member);
    getJDA().handleEvent(
        new GuildMemberJoinEvent(
            getJDA(), responseNumber,
            member));
    return null;
}
 
Example #2
Source File: GuildMemberListener.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(@Nonnull GenericEvent event) {
    if (event instanceof GuildMemberJoinEvent) {
        this.onGuildMemberJoin((GuildMemberJoinEvent) event);
    } else if (event instanceof GuildMemberRemoveEvent) {
        this.onGuildMemberRemove((GuildMemberRemoveEvent) event);
    } else if (event instanceof GuildMemberRoleRemoveEvent) {
        this.onGuildMemberRoleRemove((GuildMemberRoleRemoveEvent) event);
    } else if (event instanceof GuildMemberRoleAddEvent) {
        this.onGuildMemberRoleAdd((GuildMemberRoleAddEvent) event);
    }
}
 
Example #3
Source File: GuildMemberListener.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void onGuildMemberJoin(GuildMemberJoinEvent event) {
    final Guild guild = event.getGuild();
    if (event.getMember().equals(guild.getSelfMember())) {
        return;
    }

    final GuildSettings settings = GuildSettingsUtils.getGuild(guild, variables);

    if (settings.isEnableJoinMessage() && settings.getWelcomeLeaveChannel() > 0) {
        final long welcomeLeaveChannelId = settings.getWelcomeLeaveChannel();

        final TextChannel welcomeLeaveChannel = guild.getTextChannelById(welcomeLeaveChannelId);
        final String msg = parseGuildVars(settings.getCustomJoinMessage(), event);

        if (!msg.isEmpty() && !"".equals(msg.trim()) && welcomeLeaveChannel != null) {
            sendMsg(welcomeLeaveChannel, msg);
        }
    }

    if (settings.isAutoroleEnabled() && guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES)) {
        final Role r = guild.getRoleById(settings.getAutoroleRole());

        if (r != null && !guild.getPublicRole().equals(r) && guild.getSelfMember().canInteract(r)) {
            guild.addRoleToMember(event.getMember(), r).queue(null, it -> {});
        }
    }
}
 
Example #4
Source File: GuildMemberListener.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nonnull
private String parseGuildVars(String rawMessage, GenericGuildEvent event) {

    if (!(event instanceof GuildMemberJoinEvent) && !(event instanceof GuildMemberRemoveEvent)) {
        return "This code should never run";
    }

    if (rawMessage == null || "".equals(rawMessage.trim())) {
        return "";
    }

    final User user;

    if (event instanceof GuildMemberJoinEvent) {
        user = ((GuildMemberJoinEvent) event).getUser();
    } else {
        user = ((GuildMemberRemoveEvent) event).getUser();
    }

    final Guild guild = event.getGuild();
    final GuildSettings s = GuildSettingsUtils.getGuild(guild, variables);
    final long welcomeLeaveChannel = s.getWelcomeLeaveChannel();
    final Parser parser = CommandUtils.PARSER_SUPPLIER.get();

    final String message = parser.put("user", user)
        .put("guild", event.getGuild())
        .put("channel", event.getGuild().getTextChannelById(welcomeLeaveChannel))
        .put("args", "")
        .parse(rawMessage);

    parser.clear();

    return message;
}
 
Example #5
Source File: MemberListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    if (event.getMember().getUser().isBot()) {
        return;
    }
    LocalMember member = entityAccessor.getOrCreate(event.getMember());
    muteService.refreshMute(event.getMember());
    getAuditService().log(event.getGuild(), AuditActionType.MEMBER_JOIN)
            .withUser(member)
            .save();
}
 
Example #6
Source File: WelcomeUserListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    if (event.getUser().isBot()) {
        return;
    }
    Guild guild = event.getGuild();
    contextService.withContextAsync(guild, () -> {
        WelcomeMessage message = welcomeService.get(guild);
        Set<Long> roleIdsToAdd = new HashSet<>();
        if (message != null) {
            roleIdsToAdd.addAll(processWelcome(event, message));
        }

        if (Objects.equals(supportService.getSupportGuild(), event.getGuild())) {
            Role donatorRole = supportService.getDonatorRole();
            if (donatorRole != null && featureSetService.isAvailableForUser(event.getUser())) {
                roleIdsToAdd.add(donatorRole.getIdLong());
            }
        }

        if (guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES)
                && guild.getSelfMember().canInteract(event.getMember())) {
            Set<Role> roles = roleIdsToAdd.stream()
                    .map(guild::getRoleById)
                    .filter(e -> e != null && guild.getSelfMember().canInteract(e) && !e.isManaged())
                    .collect(Collectors.toSet());
            if (!roles.isEmpty()) {
                guild.modifyMemberRoles(event.getMember(), roles, null).queue();
            }
        }
    });
}
 
Example #7
Source File: PunishmentListener.java    From Arraybot with Apache License 2.0 5 votes vote down vote up
/**
 * When a member joins the guild.
 * This event is used to check if they are bypassing a mute.
 * @param event The event.
 */
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    if(event.getGuild().getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
        return;
    }
    new AbstractTask("Punishment-BypassChecker") {

        /**
         * Checks if the specified member is bypassing a punishment.
         */
        @Override
        public void onExecution() {
            Guild guild = event.getGuild();
            long user = event.getMember().getUser().getIdLong();
            boolean punish = punishmentManager.getAllPunishments(guild).stream()
                    .anyMatch(punishment -> punishment.getType() == PunishmentType.MUTE
                        && punishment.getUser() == user
                        && !punishment.isRevoked());
            if(!punish) {
                return;
            }
            Pair<Boolean, Boolean> success = UPunishment.mute(guild, user);
            if(!success.getA()) {
                logger.warn("Re-muting of {} unsuccessful.", user);
            } else {
                logger.info("{} was caught mute evading in the guild {}.", user, guild.getIdLong());
            }
        }

    }.create();
}
 
Example #8
Source File: DiscordAccountLinkListener.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    // add linked role back to people when they rejoin the server
    UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getUser().getId());
    if (uuid != null) {
        Role roleToAdd = DiscordUtil.getRoleByName(event.getMember().getGuild(), DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo"));
        if (roleToAdd != null) DiscordUtil.addRoleToMember(event.getMember(), roleToAdd);
        else DiscordSRV.debug("Couldn't add user to null role");
    }
}
 
Example #9
Source File: MemberListener.java    From Arraybot with Apache License 2.0 4 votes vote down vote up
/**
 * The event fired when a member joins a guild.
 * @param event The event.
 */
@Override
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
    handleMemberMessages(event, true);
    assignAutoRole(event.getMember());
}