Added persistent shuffle and repeat, began work on a rocket league command.

This commit is contained in:
Andrew Lalis 2017-08-27 20:05:14 +02:00 committed by Andrew Lalis
parent e1944c7447
commit 4ffd8c9a64
7 changed files with 54 additions and 39 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.github.andrewlalis</groupId>
<artifactId>HandieBot</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>
<build>
<plugins>
<plugin>

View File

@ -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<Permissions> 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);
}

View File

@ -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",
"<stats|rank> <steamID> [PLAYLIST]",
"Get Rocket League stats or specific competitive playlists.",
0);
}
@Override
public void execute(CommandContext context) {
}
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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"));
}
/**

View File

@ -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();
}
}
}