Java Code Examples for net.dv8tion.jda.api.events.message.MessageReceivedEvent#isFromType()

The following examples show how to use net.dv8tion.jda.api.events.message.MessageReceivedEvent#isFromType() . 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: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 5 votes vote down vote up
private void deleteMessage(MessageReceivedEvent event) {
    if (!event.isFromType(ChannelType.PRIVATE)) {
        try {
            event.getMessage().delete().queue();
        } catch (PermissionException e) {
            LOG.warn("Unable to delete message");
        }
    }
}
 
Example 2
Source File: EvalCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    //Specifically ignores the user meew0 due to a conflict between his bot (Elgyem) and Yui.
    //We both agreed to make our bots ignore eachother's .eval commands.
    if (e.getAuthor().getId().equals("66237334693085184"))  //meew0's ID
        return;

    if (!Permissions.getPermissions().isOp(e.getAuthor()))
    {
        sendMessage(e, "Sorry, this command is OP only!");
        return;
    }

    try
    {
        engine.put("event", e);
        engine.put("message", e.getMessage());
        engine.put("channel", e.getChannel());
        engine.put("args", args);
        engine.put("api", e.getJDA());
        if (e.isFromType(ChannelType.TEXT))
        {
            engine.put("guild", e.getGuild());
            engine.put("member", e.getMember());
        }

        Object out = engine.eval(
                "(function() {" +
                    "with (imports) {" +
                        e.getMessage().getContentDisplay().substring(args[0].length()) +
                    "}" +
                "})();");
        sendMessage(e, out == null ? "Executed without error." : out.toString());
    }
    catch (Exception e1)
    {
        sendMessage(e, e1.getMessage());
    }
}
 
Example 3
Source File: Command.java    From Yui with Apache License 2.0 5 votes vote down vote up
protected Message sendMessage(MessageReceivedEvent e, Message message)
{
    if(e.isFromType(ChannelType.PRIVATE))
        return e.getPrivateChannel().sendMessage(message).complete();
    else
        return e.getTextChannel().sendMessage(message).complete();
}
 
Example 4
Source File: HelpCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    if(!e.isFromType(ChannelType.PRIVATE))
    {
        e.getTextChannel().sendMessage(new MessageBuilder()
                .append(e.getAuthor())
                .append(": Help information was sent as a private message.")
                .build()).queue();
    }
    sendPrivate(e.getAuthor().openPrivateChannel().complete(), args);
}
 
Example 5
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    String requestingUser = event.getAuthor().getName();
    if (!event.getAuthor().isBot() && ((respondToDms && event.isFromType(ChannelType.PRIVATE)) ||
            !event.isFromType(ChannelType.PRIVATE))) {

        String message = event.getMessage().getContentRaw().toLowerCase();
        if (message.startsWith(commandCharacter)) {
            if (soundPlayer.isUserAllowed(requestingUser) && !soundPlayer.isUserBanned(requestingUser)) {
                final int maxLineLength = messageSizeLimit;

                //Respond
                if (message.startsWith(commandCharacter + "list")) {
                    listCommand(event, requestingUser, message, maxLineLength);
                    //If the command is not list and starts with the specified command character try and play that "command" or sound file.
                } else if (message.startsWith(commandCharacter + "help")) {
                    helpCommand(event, requestingUser);
                } else if (message.startsWith(commandCharacter + "volume")) {
                    volumeCommand(event, requestingUser, message);
                } else if (message.startsWith(commandCharacter + "stop")) {
                    stopCommand(event, requestingUser, message);
                } else if (message.startsWith(commandCharacter + "info")) {
                    infoCommand(event, requestingUser);
                } else if (message.startsWith(commandCharacter + "remove")) {
                    removeCommand(event, message);
                } else if (message.startsWith(commandCharacter + "random")) {
                    randomCommand(event, requestingUser);
                } else if (message.startsWith(commandCharacter + "entrance") ||
                        message.startsWith(commandCharacter + "leave")) {
                    entranceOrLeaveCommand(event, message);
                } else if (message.startsWith(commandCharacter + "userdetails")) {
                    userDetails(event);
                } else if (message.startsWith(commandCharacter + "url")) {
                    String[] messageSplit = event.getMessage().getContentRaw().split(" ");
                    if (messageSplit.length >= 1) {
                        String url = messageSplit[1];
                        soundPlayer.playUrlForUser(url, requestingUser);
                    }
                } else if (message.startsWith(commandCharacter) &&
                        message.length() >= (commandCharacter.length() + 1)) {
                    soundFileCommand(event, requestingUser, message);
                } else {
                    if (message.startsWith(commandCharacter) || event.isFromType(ChannelType.PRIVATE)) {
                        nonRecognizedCommand(event, requestingUser);
                    } else {
                        replyByPrivateMessage(event, "You seem to need help.");
                        helpCommand(event, requestingUser);
                    }
                }
            } else {
                if (!soundPlayer.isUserAllowed(requestingUser)) {
                    replyByPrivateMessage(event, "I don't take orders from you.");
                }
                if (soundPlayer.isUserBanned(requestingUser)) {
                    replyByPrivateMessage(event, "You've been banned from using this soundboard bot.");
                }
            }
        } else {
            addAttachedSoundFile(event);
        }
    }
}