aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon <bwaggone@umich.edu>2018-04-07 17:09:12 -0400
committerBrandon <bwaggone@umich.edu>2018-04-07 17:09:12 -0400
commit7eeb97fc307257290acfbf6ecbb055cdc5788c2b (patch)
tree4104b270ee87cde8a383cfc91ba6562f45dfe85e
parent3799c7828ad8ef2968f39e4044db36885aec1ab4 (diff)
downloadSoundChan-7eeb97fc307257290acfbf6ecbb055cdc5788c2b.tar.gz
SoundChan-7eeb97fc307257290acfbf6ecbb055cdc5788c2b.tar.bz2
SoundChan-7eeb97fc307257290acfbf6ecbb055cdc5788c2b.zip
Rename main, add properties loading
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/soundchan/AudioPlayerSendHandler.java (renamed from src/main/java/soundbot/AudioPlayerSendHandler.java)2
-rw-r--r--src/main/java/soundchan/GuildMusicManager.java (renamed from src/main/java/soundbot/GuildMusicManager.java)2
-rw-r--r--src/main/java/soundchan/Main.java (renamed from src/main/java/soundbot/Main.java)54
-rw-r--r--src/main/java/soundchan/TrackScheduler.java (renamed from src/main/java/soundbot/TrackScheduler.java)2
5 files changed, 48 insertions, 14 deletions
diff --git a/build.gradle b/build.gradle
index cbaf6bd..5ecc1c7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,4 +13,4 @@ dependencies {
runtime 'ch.qos.logback:logback-classic:1.2.3'
}
-mainClassName = 'soundbot.Main'
+mainClassName = 'soundchan.Main'
diff --git a/src/main/java/soundbot/AudioPlayerSendHandler.java b/src/main/java/soundchan/AudioPlayerSendHandler.java
index 6499aad..cd76807 100644
--- a/src/main/java/soundbot/AudioPlayerSendHandler.java
+++ b/src/main/java/soundchan/AudioPlayerSendHandler.java
@@ -1,4 +1,4 @@
-package soundbot;
+package soundchan;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
diff --git a/src/main/java/soundbot/GuildMusicManager.java b/src/main/java/soundchan/GuildMusicManager.java
index fc46756..40a0258 100644
--- a/src/main/java/soundbot/GuildMusicManager.java
+++ b/src/main/java/soundchan/GuildMusicManager.java
@@ -1,4 +1,4 @@
-package soundbot;
+package soundchan;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
diff --git a/src/main/java/soundbot/Main.java b/src/main/java/soundchan/Main.java
index 2255c68..80430ba 100644
--- a/src/main/java/soundbot/Main.java
+++ b/src/main/java/soundchan/Main.java
@@ -1,4 +1,4 @@
-package soundbot;
+package soundchan;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
@@ -11,6 +11,7 @@ import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Guild;
+import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
@@ -18,18 +19,44 @@ import net.dv8tion.jda.client.events.call.voice.CallVoiceJoinEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.managers.AudioManager;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
public class Main extends ListenerAdapter {
public static void main(String[] args) throws Exception {
+
+ Properties properties = LoadProperties();
+
JDA jda = new JDABuilder(AccountType.BOT)
- .setToken(System.getProperty("botToken"))
+ .setToken(properties.getProperty("botToken"))
.buildBlocking();
jda.addEventListener(new Main());
}
+ private static Properties LoadProperties(){
+ Properties properties = new Properties();
+ InputStream input = null;
+ try{
+ input = new FileInputStream("soundchan.properties");
+ properties.load(input);
+
+ }catch (IOException ex){
+ ex.printStackTrace();
+ } finally {
+ try {
+ input.close();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ return properties;
+ }
+
private final AudioPlayerManager playerManager;
private final Map<Long, GuildMusicManager> musicManagers;
@@ -64,20 +91,27 @@ public class Main extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) {
String[] command = event.getMessage().getContentRaw().split(" ", 2);
Guild guild = event.getGuild();
+ MessageChannel channel = null;
+
+ // This means SoundChan was DM'd
+ if (guild == null){
+ channel = event.getPrivateChannel();
+ }else{
+ channel = event.getTextChannel();
+ }
- if (guild != null) {
- if ("~play".equals(command[0]) && command.length == 2) {
+ if(guild != null){
+ if ("~play".equals(command[0]) && command.length == 2) {
loadAndPlay(event.getTextChannel(), command[1]);
- } else if ("~skip".equals(command[0])) {
+ } else if ("~skip".equals(command[0])) {
skipTrack(event.getTextChannel());
- } else if ("~volume".equals(command[0]) && command.length == 2) {
+ } else if ("~volume".equals(command[0]) && command.length == 2) {
changeVolume(event.getTextChannel(), command[1]);
- } else if ("~pause".equals(command[0])) {
+ } else if ("~pause".equals(command[0])) {
pauseTrack(event.getTextChannel());
- } else if ("~unpause".equals(command[0])) {
+ } else if ("~unpause".equals(command[0])) {
unpauseTrack(event.getTextChannel());
- }
- }
+ }}
super.onMessageReceived(event);
}
diff --git a/src/main/java/soundbot/TrackScheduler.java b/src/main/java/soundchan/TrackScheduler.java
index 4cbda71..7f1c258 100644
--- a/src/main/java/soundbot/TrackScheduler.java
+++ b/src/main/java/soundchan/TrackScheduler.java
@@ -1,4 +1,4 @@
-package soundbot;
+package soundchan;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;