aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/Main.java
diff options
context:
space:
mode:
authorMatt <mattkohls13@gmail.com>2018-04-10 22:11:08 -0400
committerGitHub <noreply@github.com>2018-04-10 22:11:08 -0400
commit442bf1ea125f6fa2209e9c20306f604125f612fe (patch)
tree6327a37aa53a70c368c103b866a3cfccac454635 /src/main/java/soundchan/Main.java
parente9010ccdbd1600065bba34a08e78c9938dc93a6e (diff)
parente9ff559c08fa0529b5c6da9cf82d0beb6e7e7e17 (diff)
downloadSoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.tar.gz
SoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.tar.bz2
SoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.zip
Merge pull request #2 from bwaggone/feature/LocalAudioFiles
Add local audio file support, including listing files
Diffstat (limited to 'src/main/java/soundchan/Main.java')
-rw-r--r--src/main/java/soundchan/Main.java40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/main/java/soundchan/Main.java b/src/main/java/soundchan/Main.java
index 3d0b9b6..2b34aca 100644
--- a/src/main/java/soundchan/Main.java
+++ b/src/main/java/soundchan/Main.java
@@ -33,10 +33,11 @@ public class Main extends ListenerAdapter {
.setToken(properties.getProperty("botToken"))
.buildBlocking();
- localFilePath = properties.getProperty("localFilePath");
jda.addEventListener(new Main());
+ localFilePath = properties.getProperty("localFilePath");
followingUser = properties.getProperty("followingUser");
+ localManager = new LocalAudioManager(localFilePath);
}
private static Properties LoadProperties(){
@@ -62,6 +63,7 @@ public class Main extends ListenerAdapter {
private Guild monitoredGuild;
private static String followingUser;
private static String localFilePath;
+ private static LocalAudioManager localManager;
private final AudioPlayerManager playerManager;
private final Map<Long, GuildMusicManager> musicManagers;
@@ -73,20 +75,6 @@ public class Main extends ListenerAdapter {
AudioSourceManagers.registerLocalSource(playerManager);
}
- private synchronized GuildMusicManager getGuildAudioPlayer(Guild guild) {
- long guildId = Long.parseLong(guild.getId());
- GuildMusicManager musicManager = musicManagers.get(guildId);
-
- if (musicManager == null) {
- musicManager = new GuildMusicManager(playerManager);
- musicManagers.put(guildId, musicManager);
- }
-
- guild.getAudioManager().setSendingHandler(musicManager.getSendHandler());
-
- return musicManager;
- }
-
private synchronized GuildMusicManager getGuildAudioPlayer() {
long guildId = monitoredGuildId;
GuildMusicManager musicManager = musicManagers.get(guildId);
@@ -141,7 +129,13 @@ public class Main extends ListenerAdapter {
// "!" Signifies that you're looking to play a sound effect
if(command[0].startsWith("!") && command[0].length() > 1){
- loadAndPlay(channel, localFilePath + "\\" + command[0].substring(1) + ".mp3");
+ String filepath = localManager.GetFilePath(command[0].substring(1));
+ if(!filepath.contentEquals("")) {
+ loadAndPlay(channel, filepath);
+ }
+ else{
+ channel.sendMessage("File \"" + command[0].substring(1) + "\" not found!").queue();
+ }
}
// "~" Signifies that you're looking to play a song/sound from a url
@@ -157,7 +151,14 @@ public class Main extends ListenerAdapter {
} else if ("~unpause".equals(command[0])) {
unpauseTrack(channel);
} else if ("~list".equals(command[0])) {
- listTracks(channel);
+ if(command.length == 2){
+ if(command[1].equals("queue")){
+ listTracks(channel);
+ }
+ else if(command[1].equals("sounds")){
+ localManager.ListSounds(channel);
+ }
+ }
}
}
@@ -240,7 +241,7 @@ public class Main extends ListenerAdapter {
}
private void play(Guild guild, GuildMusicManager musicManager, AudioTrack track) {
- connectToFirstVoiceChannel(guild.getAudioManager());
+ connectToFollowingVoiceChannel(guild.getAudioManager());
musicManager.scheduler.queue(track);
}
@@ -252,7 +253,8 @@ public class Main extends ListenerAdapter {
channel.sendMessage("Skipped to next track.").queue();
}
- private static void connectToFirstVoiceChannel(AudioManager audioManager) {
+
+ private static void connectToFollowingVoiceChannel(AudioManager audioManager) {
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
for (VoiceChannel voiceChannel : audioManager.getGuild().getVoiceChannels()) {
for(int i = 0; i < voiceChannel.getMembers().size(); i++) {