Skip to content

Commit

Permalink
add Rmlist command
Browse files Browse the repository at this point in the history
  • Loading branch information
Bleuzen committed Jul 25, 2020
1 parent da35bbd commit 4fe1e64
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .idea/Blizcord.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/com/github/bleuzen/blizcord/bot/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void init() {
commands.add(new Play());
commands.add(new Playtime());
commands.add(new Repeat());
commands.add(new Rmlist());
commands.add(new Save());
commands.add(new Search());
commands.add(new Seek());
Expand Down
3 changes: 2 additions & 1 deletion src/com/github/bleuzen/blizcord/bot/commands/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void execute(String arg, User author, MessageChannel channel, Guild guild
+ "!save <playlist> (Save the current playlist)\n"
+ "!load <playlist> (Load a saved playlist)\n"
+ "!loadshuffle <playlist> (Load a list and shuffle it)\n"
+ "!lists (List the saved playlists)\n"
+ "!rmlist <playlist> (Delete a saved playlist)\n"
+ "!lists (List all saved playlists)\n"
+ "!pause (Pause or resume the current track)\n"
+ "!stop (Stop the playback and clear the playlist)\n"
+ "!volume (Change the playback volume)\n"
Expand Down
50 changes: 50 additions & 0 deletions src/com/github/bleuzen/blizcord/bot/commands/Rmlist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.bleuzen.blizcord.bot.commands;

import com.github.bleuzen.blizcord.Config;
import com.github.bleuzen.blizcord.bot.AudioPlayerThread;
import com.github.bleuzen.blizcord.bot.Bot;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;

class Rmlist extends Command {

@Override
public String getName() {
return "rmlist";
}

@Override
public boolean isAdminOnly() {
return true;
}

@Override
public void execute(String arg, User author, MessageChannel channel, Guild guild) {
// arg = playlist
if(arg == null) {
channel.sendMessage(author.getAsMention() + " ``Please specify a playlist name. Put it behind this command.``").queue();
return;
}
File playlistFile = new File(new File(Config.getAppDir(), "playlists"), arg);
if(!playlistFile.exists()) {
channel.sendMessage(author.getAsMention() + " Playlist doesn't exist: ``" + arg + "``").queue();
return;
}
try {
playlistFile.delete();
channel.sendMessage(author.getAsMention() + " Playlist deleted: ``" + arg + "``").queue();
} catch (Exception e) {
channel.sendMessage(author.getAsMention() + " Failed to delete playlist: ``" + arg + "``").queue();
}
}

}

0 comments on commit 4fe1e64

Please sign in to comment.