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

The following examples show how to use net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent. 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: 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 #2
Source File: GuildMemberListener.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void onGuildMemberRemove(GuildMemberRemoveEvent event) {
    final Guild guild = event.getGuild();
    final User user = event.getUser();
    final SelfUser selfUser = event.getJDA().getSelfUser();

    // If we are leaving we need to ignore this as we cannot send messages to any channels
    // when this event is fired
    if (user.equals(selfUser)) {
        return;
    }

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

    // If the leave message is enabled and we have a welcome channel
    if (settings.isEnableJoinMessage() && settings.getWelcomeLeaveChannel() > 0) {
        final long welcomeLeaveChannelId = settings.getWelcomeLeaveChannel();

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

        // If we have a message and the text channel is not null
        if (!msg.isEmpty() && !"".equals(msg.trim()) && welcomeLeaveChannel != null) {
            sendMsg(welcomeLeaveChannel, msg);
        }
    }

    if (guild.getIdLong() == Settings.SUPPORT_GUILD_ID) {
        handlePatronRemoval(user.getIdLong());
    }
}
 
Example #3
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;
}