Skip to content

Commit

Permalink
deps update and small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jagrosh committed Jul 4, 2020
1 parent c5a583b commit 27fd75a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.49</version>
<version>1.3.50</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
Expand Down
56 changes: 29 additions & 27 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;

Expand Down Expand Up @@ -138,7 +137,7 @@ public void load()
if(owner<=0)
{
prompt.alert(Prompt.Level.ERROR, CONTEXT, "Invalid User ID! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
System.exit(0);
return;
}
else
{
Expand All @@ -147,31 +146,7 @@ public void load()
}

if(write)
{
String original = OtherUtil.loadResource(this, "/reference.conf");
byte[] bytes;
if(original==null)
{
bytes = ("token = "+token+"\r\nowner = "+owner).getBytes();
}
else
{
bytes = original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN))
.replace("BOT_TOKEN_HERE", token)
.replace("0 // OWNER ID", Long.toString(owner))
.trim().getBytes();
}
try
{
Files.write(path, bytes);
}
catch(IOException ex)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "Failed to write new config options to config.txt: "+ex
+ "\nPlease make sure that the files are not on your desktop or some other restricted area.\n\nConfig Location: "
+ path.toAbsolutePath().toString());
}
}
writeToFile();

// if we get through the whole config, it's good to go
valid = true;
Expand All @@ -182,6 +157,33 @@ public void load()
}
}

private void writeToFile()
{
String original = OtherUtil.loadResource(this, "/reference.conf");
byte[] bytes;
if(original==null)
{
bytes = ("token = "+token+"\r\nowner = "+owner).getBytes();
}
else
{
bytes = original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN))
.replace("BOT_TOKEN_HERE", token)
.replace("0 // OWNER ID", Long.toString(owner))
.trim().getBytes();
}
try
{
Files.write(path, bytes);
}
catch(IOException ex)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "Failed to write new config options to config.txt: "+ex
+ "\nPlease make sure that the files are not on your desktop or some other restricted area.\n\nConfig Location: "
+ path.toAbsolutePath().toString());
}
}

public boolean isValid()
{
return valid;
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public static void main(String[] args)
Prompt prompt = new Prompt("JMusicBot", "Switching to nogui mode. You can manually start in nogui mode by including the -Dnogui=true flag.",
"true".equalsIgnoreCase(System.getProperty("nogui", "false")));

// check deprecated nogui mode (new way of setting it is -Dnogui=true)
for(String arg: args)
if("-nogui".equalsIgnoreCase(arg))
{
prompt.alert(Prompt.Level.WARNING, "GUI", "The -nogui flag has been deprecated. "
+ "Please use the -Dnogui=true flag before the name of the jar. Example: java -jar -Dnogui=true JMusicBot.jar");
break;
}

// get and check latest version
String version = OtherUtil.checkVersion(prompt);

Expand Down

0 comments on commit 27fd75a

Please sign in to comment.