Skip to content

Commit 081509b

Browse files
authored
Merge pull request #132 from Frederikam/dev
Release v2.2
2 parents 9e810ed + a138a7b commit 081509b

File tree

17 files changed

+445
-109
lines changed

17 files changed

+445
-109
lines changed

.travis.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: java
2+
3+
addons:
4+
sonarcloud:
5+
organization: "fredboat"
6+
7+
env:
8+
global:
9+
- BUILD_NUMBER: "$TRAVIS_BUILD_NUMBER"
10+
11+
cache:
12+
directories:
13+
- "$HOME/.m2"
14+
- "$HOME/.gradle"
15+
- ".gradle/wrapper"
16+
- ".gradle/caches"
17+
- "$HOME/.sonar/cache"
18+
19+
stages:
20+
- sonar
21+
22+
jobs:
23+
fast_finish: true
24+
include:
25+
- stage: sonar
26+
jdk: openjdk8
27+
if: env(TRAVIS_SECURE_ENV_VARS) = true
28+
before_script:
29+
#for full sonar cloud blame information
30+
- "git fetch --unshallow"
31+
script:
32+
- "./gradlew sonarqube -PincludeAnalysis"

IMPLEMENTATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Make the player seek to a position of the track. Position is in millis
9595
}
9696
```
9797

98-
Set player volume. Volume may range from 0 to 150. 100 is default.
98+
Set player volume. Volume may range from 0 to 1000. 100 is default.
9999
```json
100100
{
101101
"op": "volume",

LavalinkClient/src/main/java/lavalink/client/player/LavalinkPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void seekTo(long position) {
171171

172172
@Override
173173
public void setVolume(int volume) {
174-
volume = Math.min(150, Math.max(0, volume)); // Lavaplayer bounds
174+
volume = Math.min(1000, Math.max(0, volume)); // Lavaplayer bounds
175175
this.volume = volume;
176176

177177
LavalinkSocket node = link.getNode(false);

LavalinkServer/application.yml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
server: # REST server
22
port: 2333
33
address: 0.0.0.0
4+
spring:
5+
main:
6+
banner-mode: log
47
lavalink:
58
server:
69
password: "youshallnotpass"

LavalinkServer/build.gradle

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
2+
13
apply plugin: 'application'
24
apply plugin: 'org.springframework.boot'
35
apply plugin: 'com.gorylenko.gradle-git-properties'
46

57
description = 'Play audio to discord voice channels'
68
mainClassName = "lavalink.server.Launcher"
7-
version '2.1'
9+
version '2.2'
810
ext {
911
moduleName = 'Lavalink-Server'
1012
}
@@ -25,6 +27,10 @@ bootRun {
2527
}
2628
}
2729

30+
test {
31+
useJUnitPlatform()
32+
}
33+
2834
dependencies {
2935
compile group: 'com.sedmelluq', name: 'lavaplayer', version: lavaplayerVersion
3036
compile group: 'com.github.DV8FromTheWorld', name: 'JDA-Audio', version: jdaAudioVersion
@@ -45,6 +51,19 @@ dependencies {
4551
compile group: 'io.prometheus', name: 'simpleclient_servlet', version: prometheusVersion
4652
}
4753

54+
processResources {
55+
//inject values into app.properties
56+
filesMatching("**/app.properties") {
57+
filter ReplaceTokens, tokens: [
58+
"project.version" : project.version,
59+
"project.groupId" : project.group,
60+
"project.artifactId": project.ext.moduleName,
61+
"env.BUILD_NUMBER" : (System.getenv('CI') ? System.getenv('BUILD_NUMBER') : 'DEV'),
62+
"env.BUILD_TIME" : System.currentTimeMillis() + ''
63+
]
64+
}
65+
}
66+
4867
//create a simple version file that we will be reading to create appropriate docker tags
4968
void versionTxt() {
5069
new File("$projectDir/VERSION.txt").text = "$project.version\n"

LavalinkServer/src/main/java/lavalink/server/Launcher.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
package lavalink.server;
2424

2525
import ch.qos.logback.classic.LoggerContext;
26+
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
2627
import io.sentry.Sentry;
2728
import io.sentry.SentryClient;
2829
import io.sentry.logback.SentryAppender;
2930
import lavalink.server.config.ServerConfig;
31+
import lavalink.server.info.AppInfo;
32+
import lavalink.server.info.GitRepoState;
3033
import lavalink.server.io.SocketServer;
3134
import lavalink.server.util.SimpleLogToSLF4JAdapter;
3235
import net.dv8tion.jda.utils.SimpleLog;
@@ -35,9 +38,14 @@
3538
import org.springframework.boot.SpringApplication;
3639
import org.springframework.boot.WebApplicationType;
3740
import org.springframework.boot.autoconfigure.SpringBootApplication;
41+
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
42+
import org.springframework.boot.context.event.ApplicationFailedEvent;
3843
import org.springframework.context.annotation.ComponentScan;
3944

4045
import java.io.IOException;
46+
import java.time.Instant;
47+
import java.time.ZoneId;
48+
import java.time.format.DateTimeFormatter;
4149
import java.util.Properties;
4250

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

5159
public static void main(String[] args) {
60+
if (args.length > 0
61+
&& (args[0].equalsIgnoreCase("-v")
62+
|| args[0].equalsIgnoreCase("--version"))) {
63+
System.out.println("Version flag detected. Printing version info, then exiting.");
64+
System.out.println(getVersionInfo());
65+
return;
66+
}
67+
5268
SpringApplication sa = new SpringApplication(Launcher.class);
5369
sa.setWebApplicationType(WebApplicationType.SERVLET);
70+
sa.addListeners(
71+
event -> {
72+
if (event instanceof ApplicationEnvironmentPreparedEvent) {
73+
log.info(getVersionInfo());
74+
}
75+
},
76+
event -> {
77+
if (event instanceof ApplicationFailedEvent) {
78+
ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
79+
log.error("Application failed", failed.getException());
80+
}
81+
}
82+
);
5483
sa.run(args);
5584
}
5685

@@ -102,4 +131,46 @@ private void turnOffSentry() {
102131
Sentry.close();
103132
sentryAppender.stop();
104133
}
134+
135+
private static String getVersionInfo() {
136+
AppInfo appInfo = new AppInfo();
137+
GitRepoState gitRepoState = new GitRepoState();
138+
139+
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss z")
140+
.withZone(ZoneId.of("Europe/Copenhagen"));
141+
String buildTime = dtf.format(Instant.ofEpochMilli(appInfo.getBuildTime()));
142+
String commitTime = dtf.format(Instant.ofEpochMilli(gitRepoState.getCommitTime() * 1000));
143+
144+
return "\n\n" + getVanity()
145+
+ "\n"
146+
+ "\n\tVersion: " + appInfo.getVersion()
147+
+ "\n\tBuild: " + appInfo.getBuildNumber()
148+
+ "\n\tBuild time: " + buildTime
149+
+ "\n\tBranch " + gitRepoState.getBranch()
150+
+ "\n\tCommit: " + gitRepoState.getCommitIdAbbrev()
151+
+ "\n\tCommit time: " + commitTime
152+
+ "\n\tJVM: " + System.getProperty("java.version")
153+
+ "\n\tLavaplayer " + PlayerLibrary.VERSION
154+
+ "\n";
155+
}
156+
157+
private static String getVanity() {
158+
//ansi color codes
159+
String red = "";
160+
String green = "";
161+
String defaultC = "";
162+
163+
String vanity
164+
= "g . r _ _ _ _ g__ _ _\n"
165+
+ "g /\\\\ r| | __ ___ ____ _| (_)_ __ | | __g\\ \\ \\ \\\n"
166+
+ "g ( ( )r| |/ _` \\ \\ / / _` | | | '_ \\| |/ /g \\ \\ \\ \\\n"
167+
+ "g \\\\/ r| | (_| |\\ V / (_| | | | | | | < g ) ) ) )\n"
168+
+ "g ' r|_|\\__,_| \\_/ \\__,_|_|_|_| |_|_|\\_\\g / / / /\n"
169+
+ "d =========================================g/_/_/_/d";
170+
171+
vanity = vanity.replaceAll("r", red);
172+
vanity = vanity.replaceAll("g", green);
173+
vanity = vanity.replaceAll("d", defaultC);
174+
return vanity;
175+
}
105176
}

LavalinkServer/src/main/java/lavalink/server/config/AudioPlayerConfiguration.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,45 @@
1313
import org.springframework.context.annotation.Bean;
1414
import org.springframework.stereotype.Component;
1515

16+
import java.util.function.Supplier;
17+
1618
/**
1719
* Created by napster on 05.03.18.
1820
*/
1921
@Component
2022
public class AudioPlayerConfiguration {
2123

2224
@Bean
23-
public AudioPlayerManager audioPlayerManager(AudioSourcesConfig sources, ServerConfig serverConfig) {
24-
25-
AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();
26-
27-
if (serverConfig.isGcWarnings()) {
28-
audioPlayerManager.enableGcMonitoring();
29-
}
30-
31-
if (sources.isYoutube()) {
32-
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
33-
Integer playlistLoadLimit = serverConfig.getYoutubePlaylistLoadLimit();
34-
35-
if (playlistLoadLimit != null) youtube.setPlaylistPageCount(playlistLoadLimit);
36-
audioPlayerManager.registerSourceManager(youtube);
37-
}
38-
if (sources.isBandcamp()) audioPlayerManager.registerSourceManager(new BandcampAudioSourceManager());
39-
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager());
40-
if (sources.isTwitch()) audioPlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
41-
if (sources.isVimeo()) audioPlayerManager.registerSourceManager(new VimeoAudioSourceManager());
42-
if (sources.isMixer()) audioPlayerManager.registerSourceManager(new BeamAudioSourceManager());
43-
if (sources.isHttp()) audioPlayerManager.registerSourceManager(new HttpAudioSourceManager());
44-
if (sources.isLocal()) audioPlayerManager.registerSourceManager(new LocalAudioSourceManager());
45-
46-
return audioPlayerManager;
25+
public Supplier<AudioPlayerManager> audioPlayerManagerSupplier(AudioSourcesConfig sources, ServerConfig serverConfig) {
26+
return () -> {
27+
AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();
28+
29+
if (serverConfig.isGcWarnings()) {
30+
audioPlayerManager.enableGcMonitoring();
31+
}
32+
33+
if (sources.isYoutube()) {
34+
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
35+
Integer playlistLoadLimit = serverConfig.getYoutubePlaylistLoadLimit();
36+
37+
if (playlistLoadLimit != null) youtube.setPlaylistPageCount(playlistLoadLimit);
38+
audioPlayerManager.registerSourceManager(youtube);
39+
}
40+
if (sources.isBandcamp()) audioPlayerManager.registerSourceManager(new BandcampAudioSourceManager());
41+
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager());
42+
if (sources.isTwitch()) audioPlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
43+
if (sources.isVimeo()) audioPlayerManager.registerSourceManager(new VimeoAudioSourceManager());
44+
if (sources.isMixer()) audioPlayerManager.registerSourceManager(new BeamAudioSourceManager());
45+
if (sources.isHttp()) audioPlayerManager.registerSourceManager(new HttpAudioSourceManager());
46+
if (sources.isLocal()) audioPlayerManager.registerSourceManager(new LocalAudioSourceManager());
47+
48+
return audioPlayerManager;
49+
};
50+
}
51+
52+
@Bean
53+
public AudioPlayerManager restAudioPlayerManager(Supplier<AudioPlayerManager> supplier) {
54+
return supplier.get();
4755
}
4856

4957
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package lavalink.server.info;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Properties;
10+
11+
/**
12+
* Created by napster on 25.06.18.
13+
* <p>
14+
* Requires app.properties to be populated with values during the gradle build
15+
*/
16+
@Component
17+
public class AppInfo {
18+
19+
private static final Logger log = LoggerFactory.getLogger(AppInfo.class);
20+
21+
private final String version;
22+
private final String groupId;
23+
private final String artifactId;
24+
private final String buildNumber;
25+
private final long buildTime;
26+
27+
public AppInfo() {
28+
InputStream resourceAsStream = this.getClass().getResourceAsStream("/app.properties");
29+
Properties prop = new Properties();
30+
try {
31+
prop.load(resourceAsStream);
32+
} catch (IOException e) {
33+
log.error("Failed to load app.properties", e);
34+
}
35+
this.version = prop.getProperty("version");
36+
this.groupId = prop.getProperty("groupId");
37+
this.artifactId = prop.getProperty("artifactId");
38+
this.buildNumber = prop.getProperty("buildNumber");
39+
this.buildTime = Long.parseLong(prop.getProperty("buildTime"));
40+
}
41+
42+
public String getVersion() {
43+
return this.version;
44+
}
45+
46+
public String getGroupId() {
47+
return this.groupId;
48+
}
49+
50+
public String getArtifactId() {
51+
return this.artifactId;
52+
}
53+
54+
public String getBuildNumber() {
55+
return this.buildNumber;
56+
}
57+
58+
public long getBuildTime() {
59+
return this.buildTime;
60+
}
61+
62+
public String getVersionBuild() {
63+
return this.version + "_" + this.buildNumber;
64+
}
65+
}

0 commit comments

Comments
 (0)