Java Code Examples for net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent#getMember()

The following examples show how to use net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent#getMember() . 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: AudioCommand.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) throws DiscordException {
    Member member = message.getMember();
    if (member == null) {
        return false;
    }
    if (!featureSetService.isAvailable(message.getGuild())) {
        discordService.sendBonusMessage(message.getChannel().getIdLong());
        return false;
    }
    if (!playerService.hasAccess(member)) {
        throw new ValidationException("discord.command.audio.missingAccess");
    }
    if (isActiveOnly() && !playerService.isActive(message.getGuild())) {
        messageManager.onMessage(message.getChannel(), "discord.command.audio.notStarted");
        return false;
    }
    if (isChannelRestricted() && !playerService.isInChannel(member)) {
        VoiceChannel channel = playerService.getChannel(member);
        throw new ValidationException("discord.command.audio.joinChannel", channel != null ? channel.getName() : "unknown");
    }
    return doInternal(message, context, content);
}
 
Example 2
Source File: MemberMessageFilter.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final void doFilter(GuildMessageReceivedEvent event, FilterChain<GuildMessageReceivedEvent> chain) {
    try {
        if (!event.isWebhookMessage()
                && !event.getAuthor().isBot()
                && event.getMember() != null
                && event.getChannel() != null
                && event.getMessage().getType() == MessageType.DEFAULT) {
            doInternal(event, chain);
            return;
        }
    } catch (Throwable e) {
        log.warn("Unexpected filter error", e);
    }
    chain.doFilter(event);
}
 
Example 3
Source File: AudioEchoExample.java    From JDA with Apache License 2.0 6 votes vote down vote up
/**
 * Handle command without arguments.
 *
 * @param event
 *        The event for this command
 */
private void onEchoCommand(GuildMessageReceivedEvent event)
{
    // Note: None of these can be null due to our configuration with the JDABuilder!
    Member member = event.getMember();                              // Member is the context of the user for the specific guild, containing voice state and roles
    GuildVoiceState voiceState = member.getVoiceState();            // Check the current voice state of the user
    VoiceChannel channel = voiceState.getChannel();                 // Use the channel the user is currently connected to
    if (channel != null)
    {
        connectTo(channel);                                         // Join the channel of the user
        onConnecting(channel, event.getChannel());                  // Tell the user about our success
    }
    else
    {
        onUnknownChannel(event.getChannel(), "your voice channel"); // Tell the user about our failure
    }
}
 
Example 4
Source File: RemoveWarnCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) {
    LocalMember localMember = reference.getLocalMember();
    if (!StringUtils.isNumeric(query)) {
        showHelp(event, context);
        return false;
    }
    if (event.getMember() != null && Objects.equals(localMember.getUser().getUserId(), event.getMember().getUser().getId())) {
        fail(event); // do not allow remove warns from yourself
        return false;
    }

    int index;
    try {
        index = Integer.parseInt(query) - 1;
    } catch (NumberFormatException e) {
        fail(event);
        return false;
    }

    List<MemberWarning> warningList = moderationService.getWarnings(localMember);
    if (index < 0 || warningList.size() <= index) {
        messageService.onEmbedMessage(event.getChannel(), "discord.command.mod.removeWarm.empty", index + 1);
        return false;
    }
    MemberWarning warning = warningList.get(index);
    moderationService.removeWarn(warning);
    ok(event);
    return true;
}
 
Example 5
Source File: AimlServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private Request createRequest(GuildMessageReceivedEvent event, String input) {
    Request.RequestBuilder builder = Request.builder()
            .input(input)
            .attribute("dMessageEvent", event)
            .attribute("dAuthorName", event.getAuthor().getName())
            .attribute("dAuthorMention", event.getAuthor().getAsMention())
            .attribute("dAuthorAvatarUrl", event.getAuthor().getEffectiveAvatarUrl());

    if (event.getMember() != null) {
        Member member = event.getMember();
        builder
                .attribute("dAuthorName", member.getEffectiveName())
                .attribute("dAuthorMention", member.getAsMention());
    }

    if (event.getGuild() != null) {
        Guild guild = event.getGuild();
        builder
                .attribute("dGuildName", guild.getName())
                .attribute("dGuildOwnerName", guild.getOwner().getEffectiveName());
    }

    if (event.getChannel() != null) {
        TextChannel channel = event.getChannel();
        builder.attribute("dChannelName", channel.getName());
    }
    return builder.build();
}
 
Example 6
Source File: BaseCommandsService.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Transactional
public boolean isRestricted(GuildMessageReceivedEvent event, CommandConfig commandConfig) {
    if (isRestricted(commandConfig, event.getChannel())) {
        resultEmotion(event, "✋", null);
        messageService.onTempEmbedMessage(event.getChannel(), 10, "discord.command.restricted.channel");
        return true;
    }
    if (isRestricted(commandConfig, event.getMember())) {
        resultEmotion(event, "✋", null);
        messageService.onTempEmbedMessage(event.getChannel(), 10, "discord.command.restricted.roles");
        return true;
    }
    if (event.getMember() != null && commandConfig.getCoolDownMode() != CoolDownMode.NONE) {
        if (CollectionUtils.isEmpty(commandConfig.getCoolDownIgnoredRoles()) ||
                event.getMember().getRoles().stream().noneMatch(e -> commandConfig.getCoolDownIgnoredRoles().contains(e.getIdLong()))) {
            ModerationConfig moderationConfig = moderationConfigService.get(event.getGuild());
            if (!moderationService.isModerator(event.getMember())
                    || (moderationConfig != null && !moderationConfig.isCoolDownIgnored())) {
                CoolDownHolder holder = coolDownService.getCoolDownHolderMap()
                        .computeIfAbsent(event.getGuild().getIdLong(), CoolDownHolder::new);
                long duration = holder.perform(event, commandConfig);
                if (duration > 0) {
                    resultEmotion(event, "\uD83D\uDD5C", null);
                    String durationText = PrettyTimeUtils.print(duration, contextService.getLocale());
                    messageService.onTempEmbedMessage(event.getChannel(), 10,
                            "discord.command.restricted.cooldown", durationText);
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 7
Source File: DiscordGuildMessagePreProcessEvent.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public DiscordGuildMessagePreProcessEvent(GuildMessageReceivedEvent jdaEvent) {
    super(jdaEvent.getJDA(), jdaEvent);
    this.author = jdaEvent.getAuthor();
    this.channel = jdaEvent.getChannel();
    this.guild = jdaEvent.getGuild();
    this.member = jdaEvent.getMember();
    this.message = jdaEvent.getMessage();
}
 
Example 8
Source File: DiscordGuildMessagePostProcessEvent.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public DiscordGuildMessagePostProcessEvent(GuildMessageReceivedEvent jdaEvent, boolean cancelled, String processedMessage) {
    super(jdaEvent.getJDA(), jdaEvent);
    this.author = jdaEvent.getAuthor();
    this.channel = jdaEvent.getChannel();
    this.guild = jdaEvent.getGuild();
    this.member = jdaEvent.getMember();
    this.message = jdaEvent.getMessage();

    this.setCancelled(cancelled);
    this.processedMessage = processedMessage;
}
 
Example 9
Source File: DiscordGuildMessageReceivedEvent.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public DiscordGuildMessageReceivedEvent(GuildMessageReceivedEvent jdaEvent) {
    super(jdaEvent.getJDA(), jdaEvent);
    this.author = jdaEvent.getAuthor();
    this.channel = jdaEvent.getChannel();
    this.guild = jdaEvent.getGuild();
    this.member = jdaEvent.getMember();
    this.message = jdaEvent.getMessage();
}
 
Example 10
Source File: ColorCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) {
    boolean moderator = moderationService.isModerator(event.getMember());
    Member member = moderator ? reference.getMember() : event.getMember();
    if (member == null) {
        return fail(event);
    }

    String removeKeyWord = messageService.getMessage("discord.command.mod.color.remove");
    if (StringUtils.endsWithIgnoreCase(query, removeKeyWord)) {
        if (moderationService.setColor(member, null)) {
            ok(event);
        } else {
            fail(event);
        }
        return false;
    }

    Matcher matcher = COLOR_PATTERN.matcher(query);
    if (!matcher.find()) {
        String colorCommand = messageService.getMessageByLocale("discord.command.mod.color.key",
                context.getCommandLocale());
        String message = messageService.getMessage("discord.command.mod.color.help",
                context.getConfig().getPrefix(), colorCommand);
        if (moderator) {
            message += "\n" + messageService.getMessage("discord.command.mod.color.help.mod",
                    context.getConfig().getPrefix(), colorCommand);
        }
        messageService.onEmbedMessage(event.getChannel(), message);
        return false;
    }

    Member self = event.getGuild().getSelfMember();
    Role conflicting = member.getRoles().stream()
            .filter(e -> e.getColor() != null && !self.canInteract(e))
            .findAny().orElse(null);
    if (conflicting != null) {
        messageService.onError(event.getChannel(), null, "discord.command.mod.color.conflict", conflicting.getName());
        return false;
    }

    if (moderationService.setColor(member, matcher.group(1))) {
        ok(event);
    }
    return true;
}
 
Example 11
Source File: MantaroListener.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
private void onMessage(GuildMessageReceivedEvent event) {
    if (event.isWebhookMessage() || event.getMember() == null)
        return;

    //Moderation features
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    GuildData guildData = dbGuild.getData();

    //link protection
    if (guildData.isLinkProtection() && !guildData.getLinkProtectionAllowedChannels().contains(event.getChannel().getId()) &&
            !guildData.getLinkProtectionAllowedUsers().contains(event.getAuthor().getId())) {
        //Has link protection enabled, let's check if they don't have admin stuff.
        if (!event.getMember().hasPermission(Permission.ADMINISTRATOR) && !event.getMember().hasPermission(Permission.MANAGE_SERVER)) {
            //Check if invite is valid. This is async because hasInvite uses complete sometimes.
            threadPool.execute(() -> {
                //If this message has an invite and it's not an invite to the same guild it was sent on, proceed to delete.
                if (hasInvite(event.getJDA(), event.getGuild(), event.getMessage().getContentRaw())) {
                    Member bot = event.getGuild().getSelfMember();
                    Metrics.ACTIONS.labels("link_block").inc();
                    if (bot.hasPermission(event.getChannel(), Permission.MESSAGE_MANAGE) || bot.hasPermission(Permission.ADMINISTRATOR)) {
                        User author = event.getAuthor();

                        //Ignore myself.
                        if (event.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
                            return;
                        }

                        //Ignore log channel.
                        if (guildData.getGuildLogChannel() != null && event.getChannel().getId().equals(guildData.getGuildLogChannel())) {
                            return;
                        }

                        //Yes, I know the check previously done is redundant, but in case someone decides to change the laws of nature, it should do	.
                        event.getMessage().delete().queue();
                        event.getChannel().sendMessage(EmoteReference.ERROR + "**You cannot advertise here.** Deleted invite link sent by **" + author.getName() + "#" + author.getDiscriminator() + "**.").queue();
                    } else {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot remove the invite link because I don't have permission to delete messages!").queue();
                    }
                }
            });
        }
    }
}