Skip to content

Commit

Permalink
Update 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bleuzen committed Jun 14, 2017
1 parent 167e420 commit 33defba
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 24 deletions.
4 changes: 2 additions & 2 deletions dist/aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Bleuzen <supgesu at gmail dot com>

pkgname=blizcord
pkgver=0.3.2.1
pkgver=0.3.3
pkgrel=1
pkgdesc="A simple Discord bot which can play music from YouTube or local files"
arch=('any')
Expand All @@ -10,7 +10,7 @@ license=('mit')
depends=('jre8-openjdk')
install=$pkgname.install
source=("blizcord-${pkgver}.deb::https://github.com/Bleuzen/Blizcord/releases/download/${pkgver}/blizcord-${pkgver}.deb")
md5sums=('f1d93910caa3e3f8bfff92256da07144')
md5sums=('2e67360e85306c6fe1fd1f9a883953f9')

package() {
msg2 "Extracting the data.tar.xz..."
Expand Down
2 changes: 1 addition & 1 deletion dist/deb/buildDeb.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 1. Place Blizcord in opt/Blizcord

# 2. Change the version
VERSION="0.3.2.1"
VERSION="0.3.3"

sudo sh -c "echo \"Package: blizcord
Version: $VERSION
Expand Down
16 changes: 10 additions & 6 deletions src/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static void start() {
try {
controlChannel.sendMessage(Values.BOT_NAME + " v" + Values.BOT_VERSION + " started.\nType ``" + Config.get(Config.COMMAND_PREFIX) + "help`` to see all commands.").queue();
} catch (PermissionException e) {
sendToOwner("Please give me the permision to read and write in your control channel: " + controlChannel.getName());
sendMessage(guild.getOwner().getUser(), "Please give me the permision to read and write in your control channel: " + controlChannel.getName());
}
}

Expand Down Expand Up @@ -613,16 +613,20 @@ static long timeToMS(int hours, int minutes, int seconds) {

static void setGame(Game game) {
api.getPresence().setGame(game);
//Log.print("GAME UPDATE: " + game);

Log.debug("Set game to: " + game);
}

static void sendUpdateMessage() {
sendToOwner("A new version is available!\n"
+ "https://github.com/" + Values.BOT_GITHUB_REPO + "/releases");
sendMessage(guild.getOwner().getUser(),
"A new version is available!\n"
+ "https://github.com/" + Values.BOT_GITHUB_REPO + "/releases");
}

private static void sendToOwner(String msg) {
guild.getOwner().getUser().openPrivateChannel().complete().sendMessage(msg).queue();
private static void sendMessage(User user, String msg) {
user.openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage(msg).queue();
});
}

static String getTrackName(AudioTrack track) {
Expand Down
13 changes: 10 additions & 3 deletions src/Log.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import net.dv8tion.jda.core.utils.SimpleLog;
import net.dv8tion.jda.core.utils.SimpleLog.Level;

public class Log {

static void print(String msg) {
if(Values.TESTING) {
System.out.println("[" + Values.BOT_NAME + "-Testing] " + msg);
} else {
// only print if JDA logging is enabled
if(!SimpleLog.LEVEL.equals(Level.OFF)) {
System.out.println("[" + Values.BOT_NAME + "] " + msg);
}
}

static void debug(String msg) {
if(a.isDebug()) {
System.out.println("[" + Values.BOT_NAME + "] [Debug] " + msg);
}
}

}
4 changes: 3 additions & 1 deletion src/PlayerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public void run() {
do { // sleep at least one time
try {
Thread.sleep(sleepTime);
updateDelay -= sleepTime;
if(updateDelay > 0) {
updateDelay -= sleepTime;
}
} catch (InterruptedException e) {
//e.printStackTrace();
}
Expand Down
7 changes: 7 additions & 0 deletions src/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class UpdateChecker extends TimerTask {
private boolean alreadyNotified = false;

private void checkForUpdate() {
Log.debug("[Updater] Checking for updates ...");

try {
InputStream inputStream = new URL("https://api.github.com/repos/" + Values.BOT_GITHUB_REPO + "/releases/latest").openStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
Expand All @@ -23,8 +25,13 @@ private void checkForUpdate() {
String online = toVersionString(tagName);
String local = toVersionString(Values.BOT_VERSION);

Log.debug("[Updater] Online version: " + online);
Log.debug("[Updater] Local version: " + local);

int t = online.compareTo(local);

Log.debug("[Updater] Compare result: " + t);

if(t > 0) {
updateAvailable = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Values.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

public class Values {

static final boolean TESTING = false;
static final String TESTING_CONFIG = "testingConfig.json";
static final boolean DEV = false;
static final String DEV_CONFIG = "devConfig.json";

static final String BOT_VERSION = "0.3.2.1" + (TESTING ? "-dev" : "");
static final String BOT_VERSION = "0.3.3" + (DEV ? "-dev" : "");
static final String BOT_NAME = "Blizcord";
static final String BOT_DEVELOPER = "Bleuzen <[email protected]>";
static final String BOT_GITHUB_REPO = "Bleuzen/Blizcord";
Expand Down
69 changes: 61 additions & 8 deletions src/a.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@
import javax.swing.JOptionPane;
import javax.swing.UIManager;

import net.dv8tion.jda.core.utils.SimpleLog;
import net.dv8tion.jda.core.utils.SimpleLog.Level;

public class a {

private static boolean gui;
private static boolean debug;

static boolean isGui() {
return gui;
}

static boolean isDebug() {
return debug;
}

public static void main(String[] args) {
if(args.length > 0 && args[0].equalsIgnoreCase("--gui")) {
gui = true;
gui = containsArg(args, "--gui");
debug = containsArg(args, "--debug") || Values.DEV;

if(gui) {
try {
try {
if(System.getProperty("os.name").toLowerCase().equals("linux") && System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().equals("kde")) {
Expand All @@ -26,17 +36,29 @@ public static void main(String[] args) {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (Exception e) {
Log.print("Failed to set look and feel.");
Log.debug("Failed to set look and feel.");
}

Log.debug("Launching GUI ...");

// Launch GUI
GUI frame = new GUI();
frame.setVisible(true);

// disable logging
SimpleLog.LEVEL = Level.OFF;
} catch (Exception e) {
gui = false; // to print error message to System.out
errExit("Failed to start GUI: " + e.getMessage());
}
} else {
// find and set first error level (to only print errors of JDA)
for(Level logLevel : Level.values()) {
if(logLevel.isError()) {
SimpleLog.LEVEL = logLevel;
break;
}
}

launch(args);
}
}
Expand All @@ -47,13 +69,19 @@ static void launch(String[] args) {

Log.print("Starting ...");

// override log level if debug
if(debug) {
SimpleLog.LEVEL = Level.ALL;
}

// init config
File configFile;
if(Values.TESTING) {
configFile = new File(Values.TESTING_CONFIG);
if(Values.DEV) {
configFile = new File(Values.DEV_CONFIG);
} else {
if(args.length > 1 && args[0].equalsIgnoreCase("--config")) {
configFile = new File(args[1]);
String configArg = getArg(args, "--config");
if(configArg != null) {
configFile = new File(configArg);
} else {
configFile = new File(Values.DEFAULT_CONFIG);
}
Expand Down Expand Up @@ -89,6 +117,31 @@ static void errExit(String msg) {
System.exit(1);
}

private static int getArgIndex(String[] args, String arg) {
//TODO: if null?
int ir = -1; // return -1 if args does not contain the argument
for(int in = 0; in < args.length; in++) {
if(args[in].equalsIgnoreCase(arg)) {
ir = in;
break;
}
}
return ir;
}

private static boolean containsArg(String[] args, String arg) {
return getArgIndex(args, arg) != -1; //TODO: Test
}

private static String getArg(String[] args, String arg) {
String result = null; // return null if argument is not given
int i = getArgIndex(args, arg);
if(i != -1) {
result = args[i + 1];
}
return result;
}

//TODO: maybe find a better way (move to GUI class?)
static void addToServerMessage(String link) {
if(gui) {
Expand Down

0 comments on commit 33defba

Please sign in to comment.