diff --git a/pom.xml b/pom.xml index 37a1f7a..cc98129 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.andrewlalis HandieBot - 1.5.1 + 1.5.2 diff --git a/src/main/java/handiebot/HandieBot.java b/src/main/java/handiebot/HandieBot.java index a964838..46390c0 100644 --- a/src/main/java/handiebot/HandieBot.java +++ b/src/main/java/handiebot/HandieBot.java @@ -17,7 +17,10 @@ import sx.blah.discord.handle.obj.Permissions; import sx.blah.discord.util.DiscordException; import sx.blah.discord.util.RateLimitException; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; import java.util.*; /** @@ -40,6 +43,9 @@ public class HandieBot { System.exit(-1); } } + + + //Variable to enable or disable GUI. private static boolean USE_GUI = true; @@ -69,28 +75,6 @@ public class HandieBot { //The cross-guild music player. public static MusicPlayer musicPlayer; - //List of all permissions needed to operate this bot. - private static final int permissionsNumber; - static { - List requiredPermissions = new ArrayList<>(); - requiredPermissions.add(Permissions.CHANGE_NICKNAME); - requiredPermissions.add(Permissions.ADD_REACTIONS); - requiredPermissions.add(Permissions.MANAGE_CHANNELS); - requiredPermissions.add(Permissions.EMBED_LINKS); - requiredPermissions.add(Permissions.ATTACH_FILES); - requiredPermissions.add(Permissions.MANAGE_EMOJIS); - requiredPermissions.add(Permissions.MANAGE_MESSAGES); - requiredPermissions.add(Permissions.MANAGE_PERMISSIONS); - requiredPermissions.add(Permissions.READ_MESSAGE_HISTORY); - requiredPermissions.add(Permissions.READ_MESSAGES); - requiredPermissions.add(Permissions.SEND_MESSAGES); - requiredPermissions.add(Permissions.VOICE_CONNECT); - requiredPermissions.add(Permissions.VOICE_MUTE_MEMBERS); - requiredPermissions.add(Permissions.VOICE_SPEAK); - requiredPermissions.add(Permissions.VOICE_USE_VAD); - permissionsNumber = Permissions.generatePermissionsNumber(EnumSet.copyOf(requiredPermissions)); - } - @EventSubscriber public void onMessageReceived(MessageReceivedEvent event) { CommandHandler.handleCommand(event); @@ -163,11 +147,7 @@ public class HandieBot { musicPlayer.quitAll(); client.logout(); window.dispose(); - try { - settings.store(new FileWriter(FileUtil.getDataDirectory()+"settings"), "Settings for HandieBot"); - } catch (IOException e) { - e.printStackTrace(); - } + FileUtil.saveSettings(); System.exit(0); } diff --git a/src/main/java/handiebot/command/commands/misc/RLCommand.java b/src/main/java/handiebot/command/commands/misc/RLCommand.java new file mode 100644 index 0000000..b75494b --- /dev/null +++ b/src/main/java/handiebot/command/commands/misc/RLCommand.java @@ -0,0 +1,23 @@ +package handiebot.command.commands.misc; + +import handiebot.command.CommandContext; +import handiebot.command.types.ContextCommand; + +/** + * @author Andrew Lalis + * Command to fetch rocket league stats and display them in a nice way. + */ +public class RLCommand extends ContextCommand { +//TODO Finish this command, and register it with the list of commands. + public RLCommand() { + super("rl", + " [PLAYLIST]", + "Get Rocket League stats or specific competitive playlists.", + 0); + } + + @Override + public void execute(CommandContext context) { + + } +} diff --git a/src/main/java/handiebot/command/commands/music/RepeatCommand.java b/src/main/java/handiebot/command/commands/music/RepeatCommand.java index 0b097da..bc26181 100644 --- a/src/main/java/handiebot/command/commands/music/RepeatCommand.java +++ b/src/main/java/handiebot/command/commands/music/RepeatCommand.java @@ -4,6 +4,7 @@ import handiebot.HandieBot; import handiebot.command.CommandContext; import handiebot.command.Commands; import handiebot.command.types.ContextCommand; +import handiebot.utils.FileUtil; import java.text.MessageFormat; @@ -28,6 +29,8 @@ public class RepeatCommand extends ContextCommand { if (context.getArgs().length == 1 && Commands.hasPermission(context, 8)){ boolean shouldRepeat = (context.getArgs()[0].toLowerCase().equals("true")); HandieBot.musicPlayer.setRepeat(context.getGuild(), shouldRepeat); + HandieBot.settings.setProperty(context.getGuild().getName()+"_repeat", Boolean.toString(shouldRepeat)); + FileUtil.saveSettings(); } else { sendMessage(MessageFormat.format(resourceBundle.getString("player.getRepeat"), HandieBot.musicPlayer.isRepeating(context.getGuild())), context.getChannel()); } diff --git a/src/main/java/handiebot/command/commands/music/ShuffleCommand.java b/src/main/java/handiebot/command/commands/music/ShuffleCommand.java index 4a7d0cd..b663936 100644 --- a/src/main/java/handiebot/command/commands/music/ShuffleCommand.java +++ b/src/main/java/handiebot/command/commands/music/ShuffleCommand.java @@ -4,6 +4,7 @@ import handiebot.HandieBot; import handiebot.command.CommandContext; import handiebot.command.Commands; import handiebot.command.types.ContextCommand; +import handiebot.utils.FileUtil; import java.text.MessageFormat; @@ -26,8 +27,11 @@ public class ShuffleCommand extends ContextCommand { @Override public void execute(CommandContext context) { if (context.getArgs().length == 1 && Commands.hasPermission(context, 8)){ - boolean shouldShuffle = (context.getArgs()[0].toLowerCase().equals("true")); + boolean shouldShuffle = (context.getArgs()[0].equalsIgnoreCase("true")); HandieBot.musicPlayer.setShuffle(context.getGuild(), shouldShuffle); + //Save the settings for this guild to the settings file. + HandieBot.settings.setProperty(context.getGuild().getName()+"_shuffle", Boolean.toString(shouldShuffle)); + FileUtil.saveSettings(); } else { sendMessage(MessageFormat.format(resourceBundle.getString("player.getShuffle"), HandieBot.musicPlayer.isShuffling(context.getGuild())), context.getChannel()); } diff --git a/src/main/java/handiebot/lavaplayer/TrackScheduler.java b/src/main/java/handiebot/lavaplayer/TrackScheduler.java index 544678b..d5efb8d 100644 --- a/src/main/java/handiebot/lavaplayer/TrackScheduler.java +++ b/src/main/java/handiebot/lavaplayer/TrackScheduler.java @@ -38,8 +38,8 @@ public class TrackScheduler extends AudioEventAdapter { private Playlist activePlaylist; - private boolean repeat = true; - private boolean shuffle = false; + private boolean repeat; + private boolean shuffle; private IGuild guild; @@ -52,7 +52,8 @@ public class TrackScheduler extends AudioEventAdapter { this.player = player; this.guild = guild; this.activePlaylist = new Playlist("HandieBot Active Playlist"); - //this.activePlaylist = new Playlist("HandieBot Active Playlist"); + this.repeat = Boolean.parseBoolean(HandieBot.settings.getProperty(guild.getName()+"_repeat")); + this.shuffle = Boolean.parseBoolean(HandieBot.settings.getProperty(guild.getName()+"_shuffle")); } /** diff --git a/src/main/java/handiebot/utils/FileUtil.java b/src/main/java/handiebot/utils/FileUtil.java index 5947214..5653aee 100644 --- a/src/main/java/handiebot/utils/FileUtil.java +++ b/src/main/java/handiebot/utils/FileUtil.java @@ -2,17 +2,13 @@ package handiebot.utils; import handiebot.view.BotLog; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.nio.file.Files; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; -import static handiebot.HandieBot.log; -import static handiebot.HandieBot.resourceBundle; +import static handiebot.HandieBot.*; /** * @author Andrew Lalis @@ -60,4 +56,12 @@ public class FileUtil { } } + public static void saveSettings(){ + try { + settings.store(new FileWriter(FileUtil.getDataDirectory()+"settings"), "Settings for HandieBot"); + } catch (IOException e) { + e.printStackTrace(); + } + } + }