net.dv8tion.jda.api.events.message.MessageReceivedEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.message.MessageReceivedEvent. 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 6 votes vote down vote up
private void removeCommand(MessageReceivedEvent event, String message) {
    if (event.getMember() != null) {
        boolean hasManageServerPerm = userIsAdmin(event);
        String[] messageSplit = message.split(" ");
        String soundToRemove = messageSplit[1];
        if (event.getAuthor().getName().equalsIgnoreCase(soundToRemove)
                || hasManageServerPerm) {
            SoundFile soundFileToRemove = soundPlayer.getAvailableSoundFiles().get(soundToRemove);
            if (soundFileToRemove != null) {
                try {
                    boolean fileRemoved = Files.deleteIfExists(Paths.get(soundFileToRemove.getSoundFileLocation()));
                    if (fileRemoved) {
                        replyByPrivateMessage(event, "Sound file " + soundToRemove + " was removed.");
                    } else {
                        replyByPrivateMessage(event, "Could not find sound file: " + soundToRemove + ".");
                    }
                } catch (IOException e) {
                    LOG.fatal("Could not remove sound file " + soundToRemove);
                }
            }
        } else {
            replyByPrivateMessage(event, "You do not have permission to remove sound file: " + soundToRemove + ".");
        }
    }
}
 
Example #2
Source File: UptimeCommand.java    From Yui with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    //Taken from Almighty Alpaca
    //https://github.com/Java-Discord-Bot-System/Plugin-Uptime/blob/master/src/main/java/com/almightyalpaca/discord/bot/plugin/uptime/UptimePlugin.java#L28-L42
    final long duration = ManagementFactory.getRuntimeMXBean().getUptime();

    final long years = duration / 31104000000L;
    final long months = duration / 2592000000L % 12;
    final long days = duration / 86400000L % 30;
    final long hours = duration / 3600000L % 24;
    final long minutes = duration / 60000L % 60;
    final long seconds = duration / 1000L % 60;
    // final long milliseconds = duration % 1000;

    String uptime = (years == 0 ? "" : "**" + years + "** Years, ") + (months == 0 ? "" : "**" + months + "** Months, ") + (days == 0 ? "" : "**" + days + "** Days, ") + (hours == 0 ? "" : "**" + hours + "** Hours, ")
            + (minutes == 0 ? "" : "**" + minutes + "** Minutes, ") + (seconds == 0 ? "" : "**" + seconds + "** Seconds, ") /* + (milliseconds == 0 ? "" : milliseconds + " Milliseconds, ") */;

    uptime = replaceLast(uptime, ", ", "");
    uptime = replaceLast(uptime, ",", " and");

    sendMessage(e, "I've been online for:\n" + uptime);

}
 
Example #3
Source File: InfoCommand.java    From Yui with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{

    MessageBuilder builder = new MessageBuilder();
    builder.append("__Yui Information__\n")
            .append("    **Version**:       " + YuiInfo.VERSION.toString().replace("_", "\\_") + "\n")
            .append("    **ID**:                " + e.getJDA().getSelfUser().getId() + "\n")
            .append("__Creator__\n")
            .append("    **Name**:          DV8FromTheWorld\n")
            .append("    **ID**:                107562988810027008\n")
            .append("    **Github**:        <http://code.dv8tion.net>\n")
            .append("__Development__\n")
            .append("    **Language**:   Java 8\n")
            .append("    **Library**:        JDA - v" + JDAInfo.VERSION + "\n")
            .append("    **Source**:        <https://github.com/DV8FromTheWorld/Yui>");
    sendMessage(e, builder.build());
}
 
Example #4
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 6 votes vote down vote up
private void volumeCommand(MessageReceivedEvent event, String requestingUser, String message) {
    int fadeoutIndex = message.indexOf('~');
    int newVol = Integer.parseInt(message.substring(8, (fadeoutIndex > -1) ? fadeoutIndex - 1 : message.length()));

    if (newVol >= 1 && newVol <= 100) {
        muted = false;
        soundPlayer.setSoundPlayerVolume(newVol);
        replyByPrivateMessage(event, "*Volume set to " + newVol + "%*");
        LOG.info("Volume set to " + newVol + "% by " + requestingUser + ".");
    } else if (newVol == 0) {
        muted = true;
        soundPlayer.setSoundPlayerVolume(newVol);
        replyByPrivateMessage(event, requestingUser + " muted me.");
        LOG.info("Bot muted by " + requestingUser + ".");
    }
}
 
Example #5
Source File: SearchCommand.java    From Yui with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
	String filter = null;
	switch (args[0]) {
		case ".google":
		case ".g":
			break;
		case ".wiki":
			filter = "wiki";
			break;
		case ".urban":
			filter = "site:urbandictionary.com";
			break;
		default:
			return;
	}

	List<SearchResult> results = GoogleSearch.performSearch(
			"018291224751151548851%3Ajzifriqvl1o",
			StringUtils.join(args, "+", 1, args.length)
					+ ((filter != null) ? ("+" + filter) : ""));

	sendMessage(e, results.get(0).getSuggestedReturn());
}
 
Example #6
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 6 votes vote down vote up
private void userDetails(MessageReceivedEvent event) {
    String[] messageSplit = event.getMessage().getContentRaw().split(" ");
    if (messageSplit.length >= 2) {
        String userNameOrId = messageSplit[1];
        User user = userRepository.findOneByIdOrUsernameIgnoreCase(userNameOrId, userNameOrId);
        if (user != null) {
            StringBuilder response = new StringBuilder();
            response.append("User details for ").append(userNameOrId).append("```")
                    .append("\nDiscord Id: ").append(user.getId())
                    .append("\nUsername: ").append(user.getUsername())
                    .append("\nEntrance Sound: ");
            if (user.getEntranceSound() != null) {
                response.append(user.getEntranceSound());
            }
            response.append("\nLeave Sound: ");
            if (user.getLeaveSound() != null) {
                response.append(user.getLeaveSound());
            }
            response.append("```");
            replyByPrivateMessage(event, response.toString());
        }
    }
}
 
Example #7
Source File: SoundPlayerImpl.java    From DiscordSoundboard with Apache License 2.0 6 votes vote down vote up
/**
 * Plays the fileName requested.
 *
 * @param fileName     - The name of the file to play.
 * @param event        -  The event that triggered the sound playing request. The event is used to find the channel to play
 *                     the sound back in.
 * @param repeatNumber - the number of times to repeat the sound file
 */
private void playFileForEvent(String fileName, MessageReceivedEvent event, int repeatNumber) {
    SoundFile fileToPlay = getSoundFileById(fileName);
    if (event != null) {
        Guild guild = event.getGuild();
        if (fileToPlay != null) {
            moveToUserIdsChannel(event, guild);

            File soundFile = new File(fileToPlay.getSoundFileLocation());
            playFile(soundFile, guild, repeatNumber);

            if (leaveAfterPlayback) {
                disconnectFromChannel(event.getGuild());
            }
        } else {
            event.getAuthor().openPrivateChannel().complete().sendMessage("Could not find sound to play. Requested sound: " + fileName + ".").queue();
        }
    }
}
 
Example #8
Source File: SoundPlayerImpl.java    From DiscordSoundboard with Apache License 2.0 6 votes vote down vote up
/**
 * Finds a users voice channel based on event and what guild to look in.
 *
 * @param event - The event that triggered this search. This is used to get th events author.
 * @param guild - The guild (discord server) to look in for the author.
 * @return The VoiceChannel if one is found. Otherwise return null.
 */
private VoiceChannel findUsersChannel(MessageReceivedEvent event, Guild guild) {
    VoiceChannel channel = null;

    outerloop:
    for (VoiceChannel channel1 : guild.getVoiceChannels()) {
        for (Member user : channel1.getMembers()) {
            if (user.getId().equals(event.getAuthor().getId())) {
                channel = channel1;
                break outerloop;
            }
        }
    }

    return channel;
}
 
Example #9
Source File: MyAnimeListCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    List<SearchResult> results = GoogleSearch.performSearch(
            "018291224751151548851:pwowlyhmpyc",
            StringUtils.join(args, "+", 1, args.length));

    sendMessage(e, results.get(0).getSuggestedReturn());
}
 
Example #10
Source File: MessageListener.java    From Arraybot with Apache License 2.0 5 votes vote down vote up
/**
 * When a message occurs.
 * Used to log the amount of messages.
 * @param event The event.
 */
@SuppressWarnings("unchecked")
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
    RedisCommands resource = Redis.INSTANCE.getResource();
    resource.incr(UDatabase.MESSAGES_KEY);
}
 
Example #11
Source File: AnimeNewsNetworkCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    List<SearchResult> results = GoogleSearch.performSearch(
            "018291224751151548851:g6kjw0k_cp8",
            StringUtils.join(args, "+", 1, args.length));

    sendMessage(e, handleSearch(results.get(0)));
}
 
Example #12
Source File: TodoCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
private void handleCreate(MessageReceivedEvent e, String[] args) throws SQLException
{
    checkArgs(args, 2, "No ListName for the new todo list was provided. Usage: `" + getAliases().get(0) + " create [ListName]`");

    String label = args[2].toLowerCase();
    TodoList todoList = todoLists.get(label);

    if (todoList != null)
    {
        sendMessage(e, "A todo list already exists with the name `" + label + "`.");
        return;
    }

    PreparedStatement addTodoList = Database.getInstance().getStatement(ADD_TODO_LIST);
    addTodoList.setString(1,  label);                //Label
    addTodoList.setString(2, e.getAuthor().getId());//OwnerId
    addTodoList.setBoolean(3, false);               //Locked
    if (addTodoList.executeUpdate() == 0)
        throw new SQLException(ADD_TODO_LIST + " reported no modified rows!");

    todoList = new TodoList(Database.getAutoIncrement(addTodoList, 1), label, e.getAuthor().getId(), false);
    todoLists.put(label, todoList);
    addTodoList.clearParameters();

    sendMessage(e, "Created `" + label + "` todo list. Use `" + getAliases().get(0) + " add " + label + " [content...]` " +
            "to add entries to this todo list.");
}
 
Example #13
Source File: TodoCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
private void handleAdd(MessageReceivedEvent e, String[] args) throws SQLException
{
    checkArgs(args, 2, "No todo ListName was specified. Usage: `" + getAliases().get(0) + " add [ListName] [content...]`");
    checkArgs(args, 3, "No content was specified. Cannot create an empty todo entry!" +
            "Usage: `" + getAliases().get(0) + " add [ListName] [content...]`");

    String label = args[2].toLowerCase();
    String content = StringUtils.join(args, " ", 3, args.length);
    TodoList todoList = todoLists.get(label);

    if (todoList == null)
    {
        sendMessage(e, "Sorry, `" + label + "` isn't a known todo list. " +
                "Try using `" + getAliases().get(0) + " create " + label + "` to create a new list by this name.");
        return;
    }

    if (todoList.locked && !todoList.isAuthUser(e.getAuthor()))
    {
        sendMessage(e, "Sorry, `" + label + "` is a locked todo list and you do not have permission to modify it.");
        return;
    }

    PreparedStatement addTodoEntry = Database.getInstance().getStatement(ADD_TODO_ENTRY);
    addTodoEntry.setInt(1, todoList.id);
    addTodoEntry.setString(2, content);
    addTodoEntry.setBoolean(3, false);
    if (addTodoEntry.executeUpdate() == 0)
        throw new SQLException(ADD_TODO_ENTRY + " reported no modified rows!");

    todoList.entries.add(new TodoEntry(Database.getAutoIncrement(addTodoEntry, 1), content, false));
    addTodoEntry.clearParameters();

    sendMessage(e, "Added to `" + label + "` todo list.");
}
 
Example #14
Source File: TodoCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
private void handleLock(MessageReceivedEvent e, String[] args, boolean locked) throws SQLException
{
    checkArgs(args, 2, "No todo ListName was specified. Usage: `" + getAliases().get(0) + " lock/unlock [ListName]`");

    String label = args[2].toLowerCase();
    TodoList todoList = todoLists.get(label);
    if (todoList == null)
    {
        sendMessage(e, "Sorry, `" + label + "` isn't a known todo list.");
        return;
    }

    if (!todoList.isAuthUser(e.getAuthor()))
    {
        sendMessage(e, "Sorry, you do not have permission to lock or unlock the `" + label + "` todo list.");
        return;
    }

    PreparedStatement setTodoListLocked = Database.getInstance().getStatement(SET_TODO_LIST_LOCKED);
    setTodoListLocked.setBoolean(1, locked);
    setTodoListLocked.setInt(2, todoList.id);
    if (setTodoListLocked.executeUpdate() == 0)
        throw new SQLException(SET_TODO_LIST_LOCKED + " reported no updated rows!");
    setTodoListLocked.clearParameters();

    todoList.locked = locked;
    sendMessage(e, "The `" + label + "` todo list was `" + (locked ? "locked`" : "unlocked`"));
}
 
Example #15
Source File: TodoCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
public void handleClear(MessageReceivedEvent e, String[] args) throws SQLException
{
    checkArgs(args, 2, "No todo ListName was specified. Usage: `" + getAliases().get(0) + " clear [ListName]`");

    String label = args[2];
    TodoList todoList = todoLists.get(label);
    if (todoList == null)
    {
        sendMessage(e, "Sorry, `" + label + "` isn't a known todo list.");
        return;
    }

    if (todoList.locked && !todoList.isAuthUser(e.getAuthor()))
    {
        sendMessage(e, "Sorry, the `" + label +"` todo list is locked and you do not have permission to modify it.");
        return;
    }

    int clearedEntries = 0;
    PreparedStatement removeTodoEntry = Database.getInstance().getStatement(REMOVE_TODO_ENTRY);
    for (Iterator<TodoEntry> it = todoList.entries.iterator(); it.hasNext();)
    {
        TodoEntry todoEntry = it.next();
        if (todoEntry.checked)
        {
            removeTodoEntry.setInt(1, todoEntry.id);
            if (removeTodoEntry.executeUpdate() == 0)
                throw new SQLException(REMOVE_TODO_ENTRY + " reported no updated rows!");
            removeTodoEntry.clearParameters();

            it.remove();
            clearedEntries++;
        }
    }
    sendMessage(e, "Cleared **" + clearedEntries + "** completed entries from the `" + label + "` todo list.");
}
 
Example #16
Source File: TodoCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
public void handleRemove(MessageReceivedEvent e, String[] args) throws SQLException
{
    checkArgs(args, 2, "No todo ListName was specified. Usage: `" + getAliases().get(0) + " remove [ListName]`");

    String label = args[2].toLowerCase();
    TodoList todoList = todoLists.get(label);
    if (todoList == null)
    {
        sendMessage(e, "Sorry, `" + label + "` isn't a known todo list.");
        return;
    }

    if (todoList.locked && !todoList.isAuthUser(e.getAuthor()))
    {
        sendMessage(e, "Sorry, the `" + label +"` todo list is locked and you do not have permission to modify it.");
        return;
    }

    PreparedStatement removeTodoList = Database.getInstance().getStatement(REMOVE_TODO_LIST);
    removeTodoList.setInt(1, todoList.id);
    if (removeTodoList.executeUpdate() == 0)
        throw new SQLException(REMOVE_TODO_LIST + " reported no updated rows!");
    removeTodoList.clearParameters();

    todoLists.remove(label);
    sendMessage(e, "Deleted the `" + label + "` todo list.");
}
 
Example #17
Source File: UpdateCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    if (!Permissions.getPermissions().isOp(e.getAuthor().getId()))
    {
        sendMessage(e, Permissions.OP_REQUIRED_MESSAGE);
        return;
    }

    if (YuiInfo.hasNewBuild())
    {
        sendMessage(e, new MessageBuilder()
                .append("Updating to the latest version.\n")
                .append(YuiInfo.VERSION.toString())
                .append(" -> ")
                .append(YuiInfo.getLatestBuildVersion().toString())
                .build());
        System.exit(Yui.UPDATE_TO_LATEST_BUILD_EXITCODE);
    }
    else
    {
        sendMessage(e, new MessageBuilder()
            .append("Yui is currently up-to-date compared to the latest build.\n")
            .append("Current version: ", MessageBuilder.Formatting.BOLD)
            .append(YuiInfo.VERSION.toString())
            .build());
    }
}
 
Example #18
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 #19
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 #20
Source File: PermissionsCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    if (!Permissions.getPermissions().isOp(e.getAuthor()))
    {
        sendMessage(e, Permissions.OP_REQUIRED_MESSAGE);
        return;
    }

    if (args[0].contains(".perms") || args[0].contains(".permissions"))
    {
        args = ArrayUtils.subarray(args, 1, args.length);   //We cut off the .perms or .permissions to make the array behave as .op would
    }
    else
    {
        args[0] = args[0].replace(".", "");     //Cut off the leading .
    }

    if (args.length < 1)    //If the command sent was just '.perms', and we removed that above, then we have an array of length 0 currently.
    {
        sendMessage(e, "**Improper syntax, no permissions group provided!**");
        return;
    }
    switch (args[0])
    {
        //Only 1 case for now. Later we will have more user permissions types...probably.
        case "op":
            processOp(e, args);
            break;
        default:
            sendMessage(e, new MessageBuilder()
                    .append("**Improper syntax, unrecognized permission group:** ")
                    .append(args[0])
                    .append("\n**Provided Command:** ")
                    .append(e.getMessage().getContentDisplay())
                    .build());
            return;
    }
}
 
Example #21
Source File: PermissionsCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
/**
 * This processes the addOp commands of the format:  .perms op add/ .permission op add/ .op add
 *
 * @param args
 *          The array of arguments that represent the .perms/.permissions removed command.
 * @param e
 *          The original UserChatEvent, used to sendMessages.
 */
private void processAddOp(MessageReceivedEvent e, String[] args)
{
    if (args.length < 3 || e.getMessage().getMentionedUsers().isEmpty())
    {
        sendMessage(e, "Please provide a user!");
        return;
    }

    for (User user : e.getMessage().getMentionedUsers())
{
    try
    {
        if (Permissions.getPermissions().addOp(user.getId()))
        {
            sendMessage(e, "Successfully added " + user.getName() + " to the OPs list!");
            return;
        }
        else
        {
            sendMessage(e, user.getName() + " is already an OP!");
            return;
        }
    }
    catch (Exception e1)
    {
        sendMessage(e, new MessageBuilder()
                .append("Encountered an error when attempting to add OP.\n")
                .append("User: ").append(user.getName())
                .append("Error: ").append(e1.getClass().getName()).append("\n")
                .append("Reason: ").append(e1.getMessage())
                .build());
    }
}
}
 
Example #22
Source File: Command.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageReceivedEvent e)
{
    if (e.getAuthor().isBot() && !respondToBots())
        return;
    if (containsCommand(e.getMessage()))
        onCommand(e, commandArgs(e.getMessage()));
}
 
Example #23
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 #24
Source File: ReloadCommand.java    From Yui with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
    if (!Permissions.getPermissions().isOp(e.getAuthor()))
    {
        sendMessage(e, Permissions.OP_REQUIRED_MESSAGE);
        return;
    }

    sendMessage(e, "Restarting the bot, one moment...");
    System.exit(Yui.RESTART_EXITCODE);
}
 
Example #25
Source File: SoundPlayerImpl.java    From DiscordSoundboard with Apache License 2.0 5 votes vote down vote up
/**
 * Find the "author" of the event and join the voice channel they are in.
 *
 * @param event - The event
 */
private void moveToUserIdsChannel(MessageReceivedEvent event, Guild guild) {
    VoiceChannel channel = findUsersChannel(event, guild);

    if (channel == null) {
        event.getAuthor().openPrivateChannel().complete()
                .sendMessage("Hello @" + event.getAuthor().getName() + "! I can not find you in any Voice Channel. Are you sure you are connected to voice?.").queue();
        LOG.warn("Problem moving to requested users channel. Maybe user, " + event.getAuthor().getName() + " is not connected to Voice?");
    } else {
        moveToChannel(channel, guild);
    }
}
 
Example #26
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
private void initListener()
{
	listener = new ListenerAdapter() {
		
		
		@Override
		public void onMessageReceived(MessageReceivedEvent event)
		{
			if (event.getAuthor().isBot()) 
				return;
			analyseCard(event);
		}
	};
}
 
Example #27
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 #28
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 5 votes vote down vote up
private void helpCommand(MessageReceivedEvent event, String requestingUser) {
    LOG.info("Responding to help command. Requested by " + requestingUser + ".");
    replyByPrivateMessage(event, "You can type any of the following commands:" +
            "\n```" + commandCharacter + "list             - Returns a list of available sound files." +
            "\n" + commandCharacter + "soundFileName    - Plays the specified sound from the list." +
            "\n" + commandCharacter + "random           - Plays a random sound from the list." +
            "\n" + commandCharacter + "volume 0-100     - Sets the playback volume." +
            "\n" + commandCharacter + "stop             - Stops the sound that is currently playing." +
            "\n" + commandCharacter + "info             - Returns info about the bot." +
            "\n" + commandCharacter + "entrance userName soundFileName - Sets entrance sound for user" +
            "\n" + commandCharacter + "leave userName soundFileName - Sets leave sound for user" +
            "\n" + commandCharacter + "userDetails userName - Get details for user```");
}
 
Example #29
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 5 votes vote down vote up
private void stopCommand(MessageReceivedEvent event, String requestingUser, String message) {
    int fadeoutIndex = message.indexOf('~');
    int fadeoutTimeout = 0;
    if (fadeoutIndex > -1) {
        fadeoutTimeout = Integer.parseInt(message.substring(fadeoutIndex + 1));
    }
    LOG.info("Stop requested by " + requestingUser + " with a fadeout of " + fadeoutTimeout + " seconds");
    if (soundPlayer.stop()) {
        replyByPrivateMessage(event, "Playback stopped.");
    } else {
        replyByPrivateMessage(event, "Nothing was playing.");
    }
}
 
Example #30
Source File: ChatSoundBoardListener.java    From DiscordSoundboard with Apache License 2.0 5 votes vote down vote up
private void randomCommand(MessageReceivedEvent event, String requestingUser) {
    try {
        soundPlayer.playRandomSoundFile(requestingUser, event);
        deleteMessage(event);
    } catch (SoundPlaybackException e) {
        replyByPrivateMessage(event, "Problem playing random file:" + e);
    }
}