tracks = getMusicManager(guild).scheduler.queueList();
if (tracks.size() == 0) {
- getChatChannel(guild).sendMessage("The queue is empty. Use `"+ Commands.get("play").getUsage()+"` to add songs.");
+ getChatChannel(guild).sendMessage(MessageFormat.format(resourceBundle.getString("player.queueEmpty"), Commands.get("play").getUsage()));
} else {
if (tracks.size() > 10 && showAll) {
String result = Pastebin.paste("Current queue for discord server: "+guild.getName()+".", getMusicManager(guild).scheduler.getActivePlaylist().toString());
if (result != null && result.startsWith("https://pastebin.com/")){
- log.log(BotLog.TYPE.INFO, guild, "Queue uploaded to pastebin: "+result);
+ log.log(BotLog.TYPE.INFO, guild, MessageFormat.format(resourceBundle.getString("player.queueUploaded"), result));
//Only display the pastebin link for 10 minutes.
- new DisappearingMessage(getChatChannel(guild), "You may view the full queue by following the link: "+result+"\nNote that this link expires in 10 minutes.", 600000);
+ new DisappearingMessage(getChatChannel(guild), MessageFormat.format(resourceBundle.getString("player.pastebinLink"), result), 600000);
} else {
- log.log(BotLog.TYPE.ERROR, guild, "Unable to upload to pastebin: "+result);
+ log.log(BotLog.TYPE.ERROR, guild, MessageFormat.format(resourceBundle.getString("player.pastebinError"), result));
}
} else {
EmbedBuilder builder = new EmbedBuilder();
@@ -174,7 +176,7 @@ public class MusicPlayer {
sb.append(tracks.get(i).getURL()).append(")");
sb.append(tracks.get(i).getFormattedDuration()).append('\n');
}
- builder.appendField("Showing " + (tracks.size() <= 10 ? tracks.size() : "the first 10") + " track" + (tracks.size() > 1 ? "s" : "") + " out of "+tracks.size()+".", sb.toString(), false);
+ builder.appendField(MessageFormat.format(resourceBundle.getString("player.queueHeader"), tracks.size() <= 10 ? tracks.size() : "the first 10", tracks.size() > 1 ? "s" : "", tracks.size()), sb.toString(), false);
getChatChannel(guild).sendMessage(builder.build());
}
}
@@ -195,7 +197,7 @@ public class MusicPlayer {
//Build message.
StringBuilder sb = new StringBuilder();
if (timeUntilPlay > 0) {
- sb.append("Added **").append(track.getTitle()).append("** to the queue.");
+ sb.append(MessageFormat.format(resourceBundle.getString("player.addedToQueue"), track.getTitle()));
}
//If there's some tracks in the queue, get the time until this one plays.
if (timeUntilPlay > 0){
@@ -215,6 +217,10 @@ public class MusicPlayer {
* If possible, try to begin playing from the track scheduler's queue.
*/
public void playQueue(IGuild guild){
+ if (getMusicManager(guild).scheduler.getActivePlaylist().getTrackCount() == 0){
+ getChatChannel(guild).sendMessage(resourceBundle.getString("player.playQueueEmpty"));
+ return;
+ }
IVoiceChannel vc = this.getVoiceChannel(guild);
if (!vc.isConnected()){
vc.join();
@@ -224,16 +230,17 @@ public class MusicPlayer {
public void clearQueue(IGuild guild){
getMusicManager(guild).scheduler.clearQueue();
- getChatChannel(guild).sendMessage("Cleared the queue.");
+ getChatChannel(guild).sendMessage(resourceBundle.getString("player.queueCleared"));
}
/**
* Skips the current track.
*/
public void skipTrack(IGuild guild){
+ String message = resourceBundle.getString("player.skippingCurrent");
+ log.log(BotLog.TYPE.MUSIC, guild, message);
+ getChatChannel(guild).sendMessage(":track_next: "+message);
getMusicManager(guild).scheduler.nextTrack();
- log.log(BotLog.TYPE.MUSIC, guild, "Skipping the current track. ");
- getChatChannel(guild).sendMessage("Skipping the current track.");
}
/**
@@ -242,8 +249,9 @@ public class MusicPlayer {
*/
public void stop(IGuild guild){
getMusicManager(guild).scheduler.stop();
- getChatChannel(guild).sendMessage("Stopped playing music.");
- log.log(BotLog.TYPE.MUSIC, guild, "Stopped playing music.");
+ String message = resourceBundle.getString("player.musicStopped");
+ getChatChannel(guild).sendMessage(":stop_button: "+message);
+ log.log(BotLog.TYPE.MUSIC, guild, message);
}
/**
diff --git a/src/main/java/handiebot/lavaplayer/TrackScheduler.java b/src/main/java/handiebot/lavaplayer/TrackScheduler.java
index 525699b..39cbd2d 100644
--- a/src/main/java/handiebot/lavaplayer/TrackScheduler.java
+++ b/src/main/java/handiebot/lavaplayer/TrackScheduler.java
@@ -15,12 +15,19 @@ import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IVoiceChannel;
import sx.blah.discord.util.RequestBuffer;
+import java.text.MessageFormat;
import java.util.List;
import static handiebot.HandieBot.log;
+import static handiebot.HandieBot.resourceBundle;
/**
* @author Andrew Lalis
+ * Class to actually play music.
+ *
+ * It holds an active playlist which it uses to pull songs from, and through the {@code MusicPlayer}, the
+ * playlist can be modified.
+ *
*/
public class TrackScheduler extends AudioEventAdapter {
@@ -180,10 +187,10 @@ public class TrackScheduler extends AudioEventAdapter {
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
- log.log(BotLog.TYPE.MUSIC, this.guild, "Started audio track: "+track.getInfo().title);
+ log.log(BotLog.TYPE.MUSIC, this.guild, MessageFormat.format(resourceBundle.getString("trackSchedule.trackStarted"), track.getInfo().title));
List channels = this.guild.getChannelsByName(MusicPlayer.CHANNEL_NAME.toLowerCase());
if (channels.size() > 0){
- IMessage message = channels.get(0).sendMessage("Now playing: **"+track.getInfo().title+"** "+new UnloadedTrack(track).getFormattedDuration()+"\n"+track.getInfo().uri);
+ IMessage message = channels.get(0).sendMessage(MessageFormat.format(":arrow_forward: "+resourceBundle.getString("trackSchedule.nowPlaying"), track.getInfo().title, new UnloadedTrack(track).getFormattedDuration()));
RequestBuffer.request(() -> {message.addReaction(":thumbsup:");}).get();
RequestBuffer.request(() -> {message.addReaction(":thumbsdown:");}).get();
}
diff --git a/src/main/java/handiebot/lavaplayer/playlist/Playlist.java b/src/main/java/handiebot/lavaplayer/playlist/Playlist.java
index 538f911..a9be6b3 100644
--- a/src/main/java/handiebot/lavaplayer/playlist/Playlist.java
+++ b/src/main/java/handiebot/lavaplayer/playlist/Playlist.java
@@ -21,7 +21,7 @@ import static handiebot.HandieBot.log;
* on the playlist.
*/
public class Playlist {
-
+//TODO: externalize strings
private String name;
private List tracks;
@@ -121,7 +121,6 @@ public class Playlist {
public static int getShuffledIndex(int listLength){
float threshold = 0.2f;
int trueLength = listLength - (int)(threshold*(float)listLength);
- log.log(BotLog.TYPE.INFO, "Shuffle results: Actual size: "+listLength+", Last Usable Index: "+trueLength);
Random rand = new Random();
//TODO Add in a small gradient in chance for a song to be picked.
return rand.nextInt(trueLength);
diff --git a/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java b/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
index e2315c1..ed758f8 100644
--- a/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
+++ b/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
@@ -17,7 +17,7 @@ import static handiebot.HandieBot.log;
* This is useful for quickly loading playlists and only loading a track when it is needed.
*/
public class UnloadedTrack implements Cloneable {
-
+//TODO: externalize strings
private String title;
private String url;
private long duration;
diff --git a/src/main/java/handiebot/utils/DisappearingMessage.java b/src/main/java/handiebot/utils/DisappearingMessage.java
index f9b18aa..82aec7a 100644
--- a/src/main/java/handiebot/utils/DisappearingMessage.java
+++ b/src/main/java/handiebot/utils/DisappearingMessage.java
@@ -7,6 +7,7 @@ import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.Permissions;
import static handiebot.HandieBot.log;
+import static handiebot.HandieBot.resourceBundle;
/**
* @author Andrew Lalis
@@ -57,7 +58,7 @@ public class DisappearingMessage extends Thread implements Runnable {
if (HandieBot.hasPermission(Permissions.MANAGE_MESSAGES, message.getChannel())){
return true;
} else {
- log.log(BotLog.TYPE.ERROR, message.getGuild(), "Unable to delete message. Please ensure that the bot has MANAGE_MESSAGES enabled, especially for this channel.");
+ log.log(BotLog.TYPE.ERROR, message.getGuild(), resourceBundle.getString("log.deleteMessageError"));
return false;
}
}
diff --git a/src/main/java/handiebot/utils/FileUtil.java b/src/main/java/handiebot/utils/FileUtil.java
index 5a01126..26749bd 100644
--- a/src/main/java/handiebot/utils/FileUtil.java
+++ b/src/main/java/handiebot/utils/FileUtil.java
@@ -17,7 +17,7 @@ import static handiebot.HandieBot.log;
* Class to simplify file operations.
*/
public class FileUtil {
-
+//TODO: externalize strings
public static String getDataDirectory(){
return System.getProperty("user.home")+"/.handiebot/";
}
diff --git a/src/main/resources/Strings.properties b/src/main/resources/Strings.properties
index 5610cd0..d77710d 100644
--- a/src/main/resources/Strings.properties
+++ b/src/main/resources/Strings.properties
@@ -1,7 +1,12 @@
+#Strings for HandieBot:
+# The following strings are organized in a way that it should be intuitive how it will be used.
#Log
log.loggingIn=Logging client in...
log.init=HandieBot initialized.
log.shuttingDown=Shutting down the bot.
+log.deleteMessageError=Unable to delete message. Please ensure that the bot has MANAGE_MESSAGES enabled, especially for this channel.
+log.creatingChatChannel=No chat channel found, creating a new one.
+log.newVoiceChannel=No voice channel found, creating a new one.
#Window
window.close.question=Are you sure you want to exit and shutdown the bot?
window.close.title=Confirm shutdown
@@ -85,3 +90,20 @@ commands.command.shuffle.description=Sets shuffling.
commands.command.skip.description=Skips the current song.
#Stop
commands.command.stop.description=Stops playing music.
+#Music Player
+player.setRepeat=Set repeat to {0}
+player.setShuffle=Set shuffle to {0}
+player.queueEmpty=The queue is empty. Use `{0}` to add songs.
+player.queueUploaded=Queue uploaded to pastebin: {0}
+player.pastebinLink=You may view the full queue by following the link: {0}\nNote that this link expires in 10 minutes.
+player.pastebinError=Unable to upload to pastebin: {0}
+player.queueHeader=Showing {0} track{1} out of {2}.
+player.addedToQueue=Added **{0}** to the queue.
+player.queueCleared=Cleared the queue.
+player.skippingCurrent=Skipping the current track.
+player.musicStopped=Stopped playing music.
+player.playQueueEmpty=There's nothing in the queue to play.
+#Track scheduler
+trackSchedule.trackStarted=Started audio track: {0}
+trackSchedule.nowPlaying=Now playing: **{0}** {1}
+
diff --git a/src/main/resources/Strings_nl.properties b/src/main/resources/Strings_nl.properties
index 00d8375..b26e43d 100644
--- a/src/main/resources/Strings_nl.properties
+++ b/src/main/resources/Strings_nl.properties
@@ -80,4 +80,23 @@ commands.command.repeat.description=Sets repeating.
commands.command.shuffle.description=Sets shuffling.
commands.command.skip.description=Skips the current song.
commands.command.stop.description=Stops playing music.
+log.deleteMessageError=Unable to delete message. Please ensure that the bot has MANAGE_MESSAGES enabled, especially for this channel.
+log.creatingChatChannel=No chat channel found, creating a new one.
+log.newVoiceChannel=No voice channel found, creating a new one.
+player.setRepeat=Set repeat to {0}
+player.setShuffle=Set shuffle to {0}
+player.queueEmpty=The queue is empty. Use `{0}` to add songs.
+player.queueUploaded=Queue uploaded to pastebin: {0}
+player.pastebinLink=You may view the full queue by following the link: {0}\
+Note that this link expires in 10 minutes.
+player.pastebinError=Unable to upload to pastebin: {0}
+player.queueHeader=Showing {0} track{1} out of {2}.
+player.addedToQueue=Added **{0}** to the queue.
+player.queueCleared=Cleared the queue.
+player.skippingCurrent=Skipping the current track.
+player.musicStopped=Stopped playing music.
+trackSchedule.trackStarted=Started audio track: {0}
+trackSchedule.nowPlaying=Now playing: **{0}** {1}\
+{2}
+player.playQueueEmpty=There's nothing in the queue to play.