Skip to content

Commit

Permalink
Merge pull request #132 from Frederikam/dev
Browse files Browse the repository at this point in the history
Release v2.2
  • Loading branch information
freyacodes authored Jul 24, 2018
2 parents 9e810ed + a138a7b commit 081509b
Show file tree
Hide file tree
Showing 17 changed files with 445 additions and 109 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
language: java

addons:
sonarcloud:
organization: "fredboat"

env:
global:
- BUILD_NUMBER: "$TRAVIS_BUILD_NUMBER"

cache:
directories:
- "$HOME/.m2"
- "$HOME/.gradle"
- ".gradle/wrapper"
- ".gradle/caches"
- "$HOME/.sonar/cache"

stages:
- sonar

jobs:
fast_finish: true
include:
- stage: sonar
jdk: openjdk8
if: env(TRAVIS_SECURE_ENV_VARS) = true
before_script:
#for full sonar cloud blame information
- "git fetch --unshallow"
script:
- "./gradlew sonarqube -PincludeAnalysis"
2 changes: 1 addition & 1 deletion IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Make the player seek to a position of the track. Position is in millis
}
```

Set player volume. Volume may range from 0 to 150. 100 is default.
Set player volume. Volume may range from 0 to 1000. 100 is default.
```json
{
"op": "volume",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void seekTo(long position) {

@Override
public void setVolume(int volume) {
volume = Math.min(150, Math.max(0, volume)); // Lavaplayer bounds
volume = Math.min(1000, Math.max(0, volume)); // Lavaplayer bounds
this.volume = volume;

LavalinkSocket node = link.getNode(false);
Expand Down
3 changes: 3 additions & 0 deletions LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
server: # REST server
port: 2333
address: 0.0.0.0
spring:
main:
banner-mode: log
lavalink:
server:
password: "youshallnotpass"
Expand Down
21 changes: 20 additions & 1 deletion LavalinkServer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.gorylenko.gradle-git-properties'

description = 'Play audio to discord voice channels'
mainClassName = "lavalink.server.Launcher"
version '2.1'
version '2.2'
ext {
moduleName = 'Lavalink-Server'
}
Expand All @@ -25,6 +27,10 @@ bootRun {
}
}

test {
useJUnitPlatform()
}

dependencies {
compile group: 'com.sedmelluq', name: 'lavaplayer', version: lavaplayerVersion
compile group: 'com.github.DV8FromTheWorld', name: 'JDA-Audio', version: jdaAudioVersion
Expand All @@ -45,6 +51,19 @@ dependencies {
compile group: 'io.prometheus', name: 'simpleclient_servlet', version: prometheusVersion
}

processResources {
//inject values into app.properties
filesMatching("**/app.properties") {
filter ReplaceTokens, tokens: [
"project.version" : project.version,
"project.groupId" : project.group,
"project.artifactId": project.ext.moduleName,
"env.BUILD_NUMBER" : (System.getenv('CI') ? System.getenv('BUILD_NUMBER') : 'DEV'),
"env.BUILD_TIME" : System.currentTimeMillis() + ''
]
}
}

//create a simple version file that we will be reading to create appropriate docker tags
void versionTxt() {
new File("$projectDir/VERSION.txt").text = "$project.version\n"
Expand Down
71 changes: 71 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
package lavalink.server;

import ch.qos.logback.classic.LoggerContext;
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.logback.SentryAppender;
import lavalink.server.config.ServerConfig;
import lavalink.server.info.AppInfo;
import lavalink.server.info.GitRepoState;
import lavalink.server.io.SocketServer;
import lavalink.server.util.SimpleLogToSLF4JAdapter;
import net.dv8tion.jda.utils.SimpleLog;
Expand All @@ -35,9 +38,14 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.annotation.ComponentScan;

import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Properties;

@SpringBootApplication
Expand All @@ -49,8 +57,29 @@ public class Launcher {
public final static long startTime = System.currentTimeMillis();

public static void main(String[] args) {
if (args.length > 0
&& (args[0].equalsIgnoreCase("-v")
|| args[0].equalsIgnoreCase("--version"))) {
System.out.println("Version flag detected. Printing version info, then exiting.");
System.out.println(getVersionInfo());
return;
}

SpringApplication sa = new SpringApplication(Launcher.class);
sa.setWebApplicationType(WebApplicationType.SERVLET);
sa.addListeners(
event -> {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
log.info(getVersionInfo());
}
},
event -> {
if (event instanceof ApplicationFailedEvent) {
ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
log.error("Application failed", failed.getException());
}
}
);
sa.run(args);
}

Expand Down Expand Up @@ -102,4 +131,46 @@ private void turnOffSentry() {
Sentry.close();
sentryAppender.stop();
}

private static String getVersionInfo() {
AppInfo appInfo = new AppInfo();
GitRepoState gitRepoState = new GitRepoState();

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss z")
.withZone(ZoneId.of("Europe/Copenhagen"));
String buildTime = dtf.format(Instant.ofEpochMilli(appInfo.getBuildTime()));
String commitTime = dtf.format(Instant.ofEpochMilli(gitRepoState.getCommitTime() * 1000));

return "\n\n" + getVanity()
+ "\n"
+ "\n\tVersion: " + appInfo.getVersion()
+ "\n\tBuild: " + appInfo.getBuildNumber()
+ "\n\tBuild time: " + buildTime
+ "\n\tBranch " + gitRepoState.getBranch()
+ "\n\tCommit: " + gitRepoState.getCommitIdAbbrev()
+ "\n\tCommit time: " + commitTime
+ "\n\tJVM: " + System.getProperty("java.version")
+ "\n\tLavaplayer " + PlayerLibrary.VERSION
+ "\n";
}

private static String getVanity() {
//ansi color codes
String red = "";
String green = "";
String defaultC = "";

String vanity
= "g . r _ _ _ _ g__ _ _\n"
+ "g /\\\\ r| | __ ___ ____ _| (_)_ __ | | __g\\ \\ \\ \\\n"
+ "g ( ( )r| |/ _` \\ \\ / / _` | | | '_ \\| |/ /g \\ \\ \\ \\\n"
+ "g \\\\/ r| | (_| |\\ V / (_| | | | | | | < g ) ) ) )\n"
+ "g ' r|_|\\__,_| \\_/ \\__,_|_|_|_| |_|_|\\_\\g / / / /\n"
+ "d =========================================g/_/_/_/d";

vanity = vanity.replaceAll("r", red);
vanity = vanity.replaceAll("g", green);
vanity = vanity.replaceAll("d", defaultC);
return vanity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.function.Supplier;

/**
* Created by napster on 05.03.18.
*/
@Component
public class AudioPlayerConfiguration {

@Bean
public AudioPlayerManager audioPlayerManager(AudioSourcesConfig sources, ServerConfig serverConfig) {

AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();

if (serverConfig.isGcWarnings()) {
audioPlayerManager.enableGcMonitoring();
}

if (sources.isYoutube()) {
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
Integer playlistLoadLimit = serverConfig.getYoutubePlaylistLoadLimit();

if (playlistLoadLimit != null) youtube.setPlaylistPageCount(playlistLoadLimit);
audioPlayerManager.registerSourceManager(youtube);
}
if (sources.isBandcamp()) audioPlayerManager.registerSourceManager(new BandcampAudioSourceManager());
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager());
if (sources.isTwitch()) audioPlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
if (sources.isVimeo()) audioPlayerManager.registerSourceManager(new VimeoAudioSourceManager());
if (sources.isMixer()) audioPlayerManager.registerSourceManager(new BeamAudioSourceManager());
if (sources.isHttp()) audioPlayerManager.registerSourceManager(new HttpAudioSourceManager());
if (sources.isLocal()) audioPlayerManager.registerSourceManager(new LocalAudioSourceManager());

return audioPlayerManager;
public Supplier<AudioPlayerManager> audioPlayerManagerSupplier(AudioSourcesConfig sources, ServerConfig serverConfig) {
return () -> {
AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();

if (serverConfig.isGcWarnings()) {
audioPlayerManager.enableGcMonitoring();
}

if (sources.isYoutube()) {
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
Integer playlistLoadLimit = serverConfig.getYoutubePlaylistLoadLimit();

if (playlistLoadLimit != null) youtube.setPlaylistPageCount(playlistLoadLimit);
audioPlayerManager.registerSourceManager(youtube);
}
if (sources.isBandcamp()) audioPlayerManager.registerSourceManager(new BandcampAudioSourceManager());
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager());
if (sources.isTwitch()) audioPlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
if (sources.isVimeo()) audioPlayerManager.registerSourceManager(new VimeoAudioSourceManager());
if (sources.isMixer()) audioPlayerManager.registerSourceManager(new BeamAudioSourceManager());
if (sources.isHttp()) audioPlayerManager.registerSourceManager(new HttpAudioSourceManager());
if (sources.isLocal()) audioPlayerManager.registerSourceManager(new LocalAudioSourceManager());

return audioPlayerManager;
};
}

@Bean
public AudioPlayerManager restAudioPlayerManager(Supplier<AudioPlayerManager> supplier) {
return supplier.get();
}

}
65 changes: 65 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/info/AppInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package lavalink.server.info;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* Created by napster on 25.06.18.
* <p>
* Requires app.properties to be populated with values during the gradle build
*/
@Component
public class AppInfo {

private static final Logger log = LoggerFactory.getLogger(AppInfo.class);

private final String version;
private final String groupId;
private final String artifactId;
private final String buildNumber;
private final long buildTime;

public AppInfo() {
InputStream resourceAsStream = this.getClass().getResourceAsStream("/app.properties");
Properties prop = new Properties();
try {
prop.load(resourceAsStream);
} catch (IOException e) {
log.error("Failed to load app.properties", e);
}
this.version = prop.getProperty("version");
this.groupId = prop.getProperty("groupId");
this.artifactId = prop.getProperty("artifactId");
this.buildNumber = prop.getProperty("buildNumber");
this.buildTime = Long.parseLong(prop.getProperty("buildTime"));
}

public String getVersion() {
return this.version;
}

public String getGroupId() {
return this.groupId;
}

public String getArtifactId() {
return this.artifactId;
}

public String getBuildNumber() {
return this.buildNumber;
}

public long getBuildTime() {
return this.buildTime;
}

public String getVersionBuild() {
return this.version + "_" + this.buildNumber;
}
}
Loading

0 comments on commit 081509b

Please sign in to comment.